ld.texi 355 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346
  1. \input texinfo
  2. @setfilename ld.info
  3. @c Copyright (C) 1991-2022 Free Software Foundation, Inc.
  4. @syncodeindex ky cp
  5. @c man begin INCLUDE
  6. @include configdoc.texi
  7. @c (configdoc.texi is generated by the Makefile)
  8. @include bfdver.texi
  9. @c man end
  10. @c @smallbook
  11. @macro gcctabopt{body}
  12. @code{\body\}
  13. @end macro
  14. @c man begin NAME
  15. @ifset man
  16. @c Configure for the generation of man pages
  17. @set UsesEnvVars
  18. @set GENERIC
  19. @set ARM
  20. @set C6X
  21. @set CSKY
  22. @set H8300
  23. @set HPPA
  24. @set M68HC11
  25. @set M68K
  26. @set MIPS
  27. @set MMIX
  28. @set MSP430
  29. @set NDS32
  30. @set NIOSII
  31. @set PDP11
  32. @set POWERPC
  33. @set POWERPC64
  34. @set Renesas
  35. @set S/390
  36. @set SPU
  37. @set TICOFF
  38. @set WIN32
  39. @set XTENSA
  40. @end ifset
  41. @c man end
  42. @ifnottex
  43. @dircategory Software development
  44. @direntry
  45. * Ld: (ld). The GNU linker.
  46. @end direntry
  47. @end ifnottex
  48. @copying
  49. This file documents the @sc{gnu} linker LD
  50. @ifset VERSION_PACKAGE
  51. @value{VERSION_PACKAGE}
  52. @end ifset
  53. version @value{VERSION}.
  54. Copyright @copyright{} 1991-2022 Free Software Foundation, Inc.
  55. Permission is granted to copy, distribute and/or modify this document
  56. under the terms of the GNU Free Documentation License, Version 1.3
  57. or any later version published by the Free Software Foundation;
  58. with no Invariant Sections, with no Front-Cover Texts, and with no
  59. Back-Cover Texts. A copy of the license is included in the
  60. section entitled ``GNU Free Documentation License''.
  61. @end copying
  62. @iftex
  63. @finalout
  64. @setchapternewpage odd
  65. @settitle The GNU linker
  66. @titlepage
  67. @title The GNU linker
  68. @sp 1
  69. @subtitle @code{ld}
  70. @ifset VERSION_PACKAGE
  71. @subtitle @value{VERSION_PACKAGE}
  72. @end ifset
  73. @subtitle Version @value{VERSION}
  74. @author Steve Chamberlain
  75. @author Ian Lance Taylor
  76. @page
  77. @tex
  78. {\parskip=0pt
  79. \hfill Red Hat Inc\par
  80. \hfill nickc\@credhat.com, doc\@redhat.com\par
  81. \hfill {\it The GNU linker}\par
  82. \hfill Edited by Jeffrey Osier (jeffrey\@cygnus.com)\par
  83. }
  84. \global\parindent=0pt % Steve likes it this way.
  85. @end tex
  86. @vskip 0pt plus 1filll
  87. @c man begin COPYRIGHT
  88. Copyright @copyright{} 1991-2022 Free Software Foundation, Inc.
  89. Permission is granted to copy, distribute and/or modify this document
  90. under the terms of the GNU Free Documentation License, Version 1.3
  91. or any later version published by the Free Software Foundation;
  92. with no Invariant Sections, with no Front-Cover Texts, and with no
  93. Back-Cover Texts. A copy of the license is included in the
  94. section entitled ``GNU Free Documentation License''.
  95. @c man end
  96. @end titlepage
  97. @end iftex
  98. @contents
  99. @c FIXME: Talk about importance of *order* of args, cmds to linker!
  100. @ifnottex
  101. @node Top
  102. @top LD
  103. This file documents the @sc{gnu} linker ld
  104. @ifset VERSION_PACKAGE
  105. @value{VERSION_PACKAGE}
  106. @end ifset
  107. version @value{VERSION}.
  108. This document is distributed under the terms of the GNU Free
  109. Documentation License version 1.3. A copy of the license is included
  110. in the section entitled ``GNU Free Documentation License''.
  111. @menu
  112. * Overview:: Overview
  113. * Invocation:: Invocation
  114. * Scripts:: Linker Scripts
  115. * Plugins:: Linker Plugins
  116. @ifset GENERIC
  117. * Machine Dependent:: Machine Dependent Features
  118. @end ifset
  119. @ifclear GENERIC
  120. @ifset H8300
  121. * H8/300:: ld and the H8/300
  122. @end ifset
  123. @ifset Renesas
  124. * Renesas:: ld and other Renesas micros
  125. @end ifset
  126. @ifset ARM
  127. * ARM:: ld and the ARM family
  128. @end ifset
  129. @ifset M68HC11
  130. * M68HC11/68HC12:: ld and the Motorola 68HC11 and 68HC12 families
  131. @end ifset
  132. @ifset HPPA
  133. * HPPA ELF32:: ld and HPPA 32-bit ELF
  134. @end ifset
  135. @ifset M68K
  136. * M68K:: ld and Motorola 68K family
  137. @end ifset
  138. @ifset MIPS
  139. * MIPS:: ld and MIPS family
  140. @end ifset
  141. @ifset POWERPC
  142. * PowerPC ELF32:: ld and PowerPC 32-bit ELF Support
  143. @end ifset
  144. @ifset POWERPC64
  145. * PowerPC64 ELF64:: ld and PowerPC64 64-bit ELF Support
  146. @end ifset
  147. @ifset S/390
  148. * S/390 ELF:: ld and S/390 ELF Support
  149. @end ifset
  150. @ifset SPU
  151. * SPU ELF:: ld and SPU ELF Support
  152. @end ifset
  153. @ifset TICOFF
  154. * TI COFF:: ld and the TI COFF
  155. @end ifset
  156. @ifset WIN32
  157. * Win32:: ld and WIN32 (cygwin/mingw)
  158. @end ifset
  159. @ifset XTENSA
  160. * Xtensa:: ld and Xtensa Processors
  161. @end ifset
  162. @end ifclear
  163. @ifclear SingleFormat
  164. * BFD:: BFD
  165. @end ifclear
  166. @c Following blank line required for remaining bug in makeinfo conds/menus
  167. * Reporting Bugs:: Reporting Bugs
  168. * MRI:: MRI Compatible Script Files
  169. * GNU Free Documentation License:: GNU Free Documentation License
  170. * LD Index:: LD Index
  171. @end menu
  172. @end ifnottex
  173. @node Overview
  174. @chapter Overview
  175. @cindex @sc{gnu} linker
  176. @cindex what is this?
  177. @ifset man
  178. @c man begin SYNOPSIS
  179. ld [@b{options}] @var{objfile} @dots{}
  180. @c man end
  181. @c man begin SEEALSO
  182. ar(1), nm(1), objcopy(1), objdump(1), readelf(1) and
  183. the Info entries for @file{binutils} and
  184. @file{ld}.
  185. @c man end
  186. @end ifset
  187. @c man begin DESCRIPTION
  188. @command{ld} combines a number of object and archive files, relocates
  189. their data and ties up symbol references. Usually the last step in
  190. compiling a program is to run @command{ld}.
  191. @command{ld} accepts Linker Command Language files written in
  192. a superset of AT&T's Link Editor Command Language syntax,
  193. to provide explicit and total control over the linking process.
  194. @ifset man
  195. @c For the man only
  196. This man page does not describe the command language; see the
  197. @command{ld} entry in @code{info} for full details on the command
  198. language and on other aspects of the GNU linker.
  199. @end ifset
  200. @ifclear SingleFormat
  201. This version of @command{ld} uses the general purpose BFD libraries
  202. to operate on object files. This allows @command{ld} to read, combine, and
  203. write object files in many different formats---for example, COFF or
  204. @code{a.out}. Different formats may be linked together to produce any
  205. available kind of object file. @xref{BFD}, for more information.
  206. @end ifclear
  207. Aside from its flexibility, the @sc{gnu} linker is more helpful than other
  208. linkers in providing diagnostic information. Many linkers abandon
  209. execution immediately upon encountering an error; whenever possible,
  210. @command{ld} continues executing, allowing you to identify other errors
  211. (or, in some cases, to get an output file in spite of the error).
  212. @c man end
  213. @node Invocation
  214. @chapter Invocation
  215. @c man begin DESCRIPTION
  216. The @sc{gnu} linker @command{ld} is meant to cover a broad range of situations,
  217. and to be as compatible as possible with other linkers. As a result,
  218. you have many choices to control its behavior.
  219. @c man end
  220. @ifset UsesEnvVars
  221. @menu
  222. * Options:: Command-line Options
  223. * Environment:: Environment Variables
  224. @end menu
  225. @node Options
  226. @section Command-line Options
  227. @end ifset
  228. @cindex command line
  229. @cindex options
  230. @c man begin OPTIONS
  231. The linker supports a plethora of command-line options, but in actual
  232. practice few of them are used in any particular context.
  233. @cindex standard Unix system
  234. For instance, a frequent use of @command{ld} is to link standard Unix
  235. object files on a standard, supported Unix system. On such a system, to
  236. link a file @code{hello.o}:
  237. @smallexample
  238. ld -o @var{output} /lib/crt0.o hello.o -lc
  239. @end smallexample
  240. This tells @command{ld} to produce a file called @var{output} as the
  241. result of linking the file @code{/lib/crt0.o} with @code{hello.o} and
  242. the library @code{libc.a}, which will come from the standard search
  243. directories. (See the discussion of the @samp{-l} option below.)
  244. Some of the command-line options to @command{ld} may be specified at any
  245. point in the command line. However, options which refer to files, such
  246. as @samp{-l} or @samp{-T}, cause the file to be read at the point at
  247. which the option appears in the command line, relative to the object
  248. files and other file options. Repeating non-file options with a
  249. different argument will either have no further effect, or override prior
  250. occurrences (those further to the left on the command line) of that
  251. option. Options which may be meaningfully specified more than once are
  252. noted in the descriptions below.
  253. @cindex object files
  254. Non-option arguments are object files or archives which are to be linked
  255. together. They may follow, precede, or be mixed in with command-line
  256. options, except that an object file argument may not be placed between
  257. an option and its argument.
  258. Usually the linker is invoked with at least one object file, but you can
  259. specify other forms of binary input files using @samp{-l}, @samp{-R},
  260. and the script command language. If @emph{no} binary input files at all
  261. are specified, the linker does not produce any output, and issues the
  262. message @samp{No input files}.
  263. If the linker cannot recognize the format of an object file, it will
  264. assume that it is a linker script. A script specified in this way
  265. augments the main linker script used for the link (either the default
  266. linker script or the one specified by using @samp{-T}). This feature
  267. permits the linker to link against a file which appears to be an object
  268. or an archive, but actually merely defines some symbol values, or uses
  269. @code{INPUT} or @code{GROUP} to load other objects. Specifying a
  270. script in this way merely augments the main linker script, with the
  271. extra commands placed after the main script; use the @samp{-T} option
  272. to replace the default linker script entirely, but note the effect of
  273. the @code{INSERT} command. @xref{Scripts}.
  274. For options whose names are a single letter,
  275. option arguments must either follow the option letter without intervening
  276. whitespace, or be given as separate arguments immediately following the
  277. option that requires them.
  278. For options whose names are multiple letters, either one dash or two can
  279. precede the option name; for example, @samp{-trace-symbol} and
  280. @samp{--trace-symbol} are equivalent. Note---there is one exception to
  281. this rule. Multiple letter options that start with a lower case 'o' can
  282. only be preceded by two dashes. This is to reduce confusion with the
  283. @samp{-o} option. So for example @samp{-omagic} sets the output file
  284. name to @samp{magic} whereas @samp{--omagic} sets the NMAGIC flag on the
  285. output.
  286. Arguments to multiple-letter options must either be separated from the
  287. option name by an equals sign, or be given as separate arguments
  288. immediately following the option that requires them. For example,
  289. @samp{--trace-symbol foo} and @samp{--trace-symbol=foo} are equivalent.
  290. Unique abbreviations of the names of multiple-letter options are
  291. accepted.
  292. Note---if the linker is being invoked indirectly, via a compiler driver
  293. (e.g. @samp{gcc}) then all the linker command-line options should be
  294. prefixed by @samp{-Wl,} (or whatever is appropriate for the particular
  295. compiler driver) like this:
  296. @smallexample
  297. gcc -Wl,--start-group foo.o bar.o -Wl,--end-group
  298. @end smallexample
  299. This is important, because otherwise the compiler driver program may
  300. silently drop the linker options, resulting in a bad link. Confusion
  301. may also arise when passing options that require values through a
  302. driver, as the use of a space between option and argument acts as
  303. a separator, and causes the driver to pass only the option to the linker
  304. and the argument to the compiler. In this case, it is simplest to use
  305. the joined forms of both single- and multiple-letter options, such as:
  306. @smallexample
  307. gcc foo.o bar.o -Wl,-eENTRY -Wl,-Map=a.map
  308. @end smallexample
  309. Here is a table of the generic command-line switches accepted by the GNU
  310. linker:
  311. @table @gcctabopt
  312. @include at-file.texi
  313. @kindex -a @var{keyword}
  314. @item -a @var{keyword}
  315. This option is supported for HP/UX compatibility. The @var{keyword}
  316. argument must be one of the strings @samp{archive}, @samp{shared}, or
  317. @samp{default}. @samp{-aarchive} is functionally equivalent to
  318. @samp{-Bstatic}, and the other two keywords are functionally equivalent
  319. to @samp{-Bdynamic}. This option may be used any number of times.
  320. @kindex --audit @var{AUDITLIB}
  321. @item --audit @var{AUDITLIB}
  322. Adds @var{AUDITLIB} to the @code{DT_AUDIT} entry of the dynamic section.
  323. @var{AUDITLIB} is not checked for existence, nor will it use the DT_SONAME
  324. specified in the library. If specified multiple times @code{DT_AUDIT}
  325. will contain a colon separated list of audit interfaces to use. If the linker
  326. finds an object with an audit entry while searching for shared libraries,
  327. it will add a corresponding @code{DT_DEPAUDIT} entry in the output file.
  328. This option is only meaningful on ELF platforms supporting the rtld-audit
  329. interface.
  330. @ifclear SingleFormat
  331. @cindex binary input format
  332. @kindex -b @var{format}
  333. @kindex --format=@var{format}
  334. @cindex input format
  335. @cindex input format
  336. @item -b @var{input-format}
  337. @itemx --format=@var{input-format}
  338. @command{ld} may be configured to support more than one kind of object
  339. file. If your @command{ld} is configured this way, you can use the
  340. @samp{-b} option to specify the binary format for input object files
  341. that follow this option on the command line. Even when @command{ld} is
  342. configured to support alternative object formats, you don't usually need
  343. to specify this, as @command{ld} should be configured to expect as a
  344. default input format the most usual format on each machine.
  345. @var{input-format} is a text string, the name of a particular format
  346. supported by the BFD libraries. (You can list the available binary
  347. formats with @samp{objdump -i}.)
  348. @xref{BFD}.
  349. You may want to use this option if you are linking files with an unusual
  350. binary format. You can also use @samp{-b} to switch formats explicitly (when
  351. linking object files of different formats), by including
  352. @samp{-b @var{input-format}} before each group of object files in a
  353. particular format.
  354. The default format is taken from the environment variable
  355. @code{GNUTARGET}.
  356. @ifset UsesEnvVars
  357. @xref{Environment}.
  358. @end ifset
  359. You can also define the input format from a script, using the command
  360. @code{TARGET};
  361. @ifclear man
  362. see @ref{Format Commands}.
  363. @end ifclear
  364. @end ifclear
  365. @kindex -c @var{MRI-cmdfile}
  366. @kindex --mri-script=@var{MRI-cmdfile}
  367. @cindex compatibility, MRI
  368. @item -c @var{MRI-commandfile}
  369. @itemx --mri-script=@var{MRI-commandfile}
  370. For compatibility with linkers produced by MRI, @command{ld} accepts script
  371. files written in an alternate, restricted command language, described in
  372. @ifclear man
  373. @ref{MRI,,MRI Compatible Script Files}.
  374. @end ifclear
  375. @ifset man
  376. the MRI Compatible Script Files section of GNU ld documentation.
  377. @end ifset
  378. Introduce MRI script files with
  379. the option @samp{-c}; use the @samp{-T} option to run linker
  380. scripts written in the general-purpose @command{ld} scripting language.
  381. If @var{MRI-cmdfile} does not exist, @command{ld} looks for it in the directories
  382. specified by any @samp{-L} options.
  383. @cindex common allocation
  384. @kindex -d
  385. @kindex -dc
  386. @kindex -dp
  387. @item -d
  388. @itemx -dc
  389. @itemx -dp
  390. These three options are equivalent; multiple forms are supported for
  391. compatibility with other linkers. They assign space to common symbols
  392. even if a relocatable output file is specified (with @samp{-r}). The
  393. script command @code{FORCE_COMMON_ALLOCATION} has the same effect.
  394. @xref{Miscellaneous Commands}.
  395. @kindex --depaudit @var{AUDITLIB}
  396. @kindex -P @var{AUDITLIB}
  397. @item --depaudit @var{AUDITLIB}
  398. @itemx -P @var{AUDITLIB}
  399. Adds @var{AUDITLIB} to the @code{DT_DEPAUDIT} entry of the dynamic section.
  400. @var{AUDITLIB} is not checked for existence, nor will it use the DT_SONAME
  401. specified in the library. If specified multiple times @code{DT_DEPAUDIT}
  402. will contain a colon separated list of audit interfaces to use. This
  403. option is only meaningful on ELF platforms supporting the rtld-audit interface.
  404. The -P option is provided for Solaris compatibility.
  405. @kindex --enable-non-contiguous-regions
  406. @item --enable-non-contiguous-regions
  407. This option avoids generating an error if an input section does not
  408. fit a matching output section. The linker tries to allocate the input
  409. section to subseque nt matching output sections, and generates an
  410. error only if no output section is large enough. This is useful when
  411. several non-contiguous memory regions are available and the input
  412. section does not require a particular one. The order in which input
  413. sections are evaluated does not change, for instance:
  414. @smallexample
  415. MEMORY @{
  416. MEM1 (rwx) : ORIGIN : 0x1000, LENGTH = 0x14
  417. MEM2 (rwx) : ORIGIN : 0x1000, LENGTH = 0x40
  418. MEM3 (rwx) : ORIGIN : 0x2000, LENGTH = 0x40
  419. @}
  420. SECTIONS @{
  421. mem1 : @{ *(.data.*); @} > MEM1
  422. mem2 : @{ *(.data.*); @} > MEM2
  423. mem3 : @{ *(.data.*); @} > MEM2
  424. @}
  425. with input sections:
  426. .data.1: size 8
  427. .data.2: size 0x10
  428. .data.3: size 4
  429. results in .data.1 affected to mem1, and .data.2 and .data.3
  430. affected to mem2, even though .data.3 would fit in mem3.
  431. @end smallexample
  432. This option is incompatible with INSERT statements because it changes
  433. the way input sections are mapped to output sections.
  434. @kindex --enable-non-contiguous-regions-warnings
  435. @item --enable-non-contiguous-regions-warnings
  436. This option enables warnings when
  437. @code{--enable-non-contiguous-regions} allows possibly unexpected
  438. matches in sections mapping, potentially leading to silently
  439. discarding a section instead of failing because it does not fit any
  440. output region.
  441. @cindex entry point, from command line
  442. @kindex -e @var{entry}
  443. @kindex --entry=@var{entry}
  444. @item -e @var{entry}
  445. @itemx --entry=@var{entry}
  446. Use @var{entry} as the explicit symbol for beginning execution of your
  447. program, rather than the default entry point. If there is no symbol
  448. named @var{entry}, the linker will try to parse @var{entry} as a number,
  449. and use that as the entry address (the number will be interpreted in
  450. base 10; you may use a leading @samp{0x} for base 16, or a leading
  451. @samp{0} for base 8). @xref{Entry Point}, for a discussion of defaults
  452. and other ways of specifying the entry point.
  453. @kindex --exclude-libs
  454. @item --exclude-libs @var{lib},@var{lib},...
  455. Specifies a list of archive libraries from which symbols should not be automatically
  456. exported. The library names may be delimited by commas or colons. Specifying
  457. @code{--exclude-libs ALL} excludes symbols in all archive libraries from
  458. automatic export. This option is available only for the i386 PE targeted
  459. port of the linker and for ELF targeted ports. For i386 PE, symbols
  460. explicitly listed in a .def file are still exported, regardless of this
  461. option. For ELF targeted ports, symbols affected by this option will
  462. be treated as hidden.
  463. @kindex --exclude-modules-for-implib
  464. @item --exclude-modules-for-implib @var{module},@var{module},...
  465. Specifies a list of object files or archive members, from which symbols
  466. should not be automatically exported, but which should be copied wholesale
  467. into the import library being generated during the link. The module names
  468. may be delimited by commas or colons, and must match exactly the filenames
  469. used by @command{ld} to open the files; for archive members, this is simply
  470. the member name, but for object files the name listed must include and
  471. match precisely any path used to specify the input file on the linker's
  472. command-line. This option is available only for the i386 PE targeted port
  473. of the linker. Symbols explicitly listed in a .def file are still exported,
  474. regardless of this option.
  475. @cindex dynamic symbol table
  476. @kindex -E
  477. @kindex --export-dynamic
  478. @kindex --no-export-dynamic
  479. @item -E
  480. @itemx --export-dynamic
  481. @itemx --no-export-dynamic
  482. When creating a dynamically linked executable, using the @option{-E}
  483. option or the @option{--export-dynamic} option causes the linker to add
  484. all symbols to the dynamic symbol table. The dynamic symbol table is the
  485. set of symbols which are visible from dynamic objects at run time.
  486. If you do not use either of these options (or use the
  487. @option{--no-export-dynamic} option to restore the default behavior), the
  488. dynamic symbol table will normally contain only those symbols which are
  489. referenced by some dynamic object mentioned in the link.
  490. If you use @code{dlopen} to load a dynamic object which needs to refer
  491. back to the symbols defined by the program, rather than some other
  492. dynamic object, then you will probably need to use this option when
  493. linking the program itself.
  494. You can also use the dynamic list to control what symbols should
  495. be added to the dynamic symbol table if the output format supports it.
  496. See the description of @samp{--dynamic-list}.
  497. Note that this option is specific to ELF targeted ports. PE targets
  498. support a similar function to export all symbols from a DLL or EXE; see
  499. the description of @samp{--export-all-symbols} below.
  500. @kindex --export-dynamic-symbol=@var{glob}
  501. @cindex export dynamic symbol
  502. @item --export-dynamic-symbol=@var{glob}
  503. When creating a dynamically linked executable, symbols matching
  504. @var{glob} will be added to the dynamic symbol table. When creating a
  505. shared library, references to symbols matching @var{glob} will not be
  506. bound to the definitions within the shared library. This option is a
  507. no-op when creating a shared library and @samp{-Bsymbolic} or
  508. @samp{--dynamic-list} are not specified. This option is only meaningful
  509. on ELF platforms which support shared libraries.
  510. @kindex --export-dynamic-symbol-list=@var{file}
  511. @cindex export dynamic symbol list
  512. @item --export-dynamic-symbol-list=@var{file}
  513. Specify a @samp{--export-dynamic-symbol} for each pattern in the file.
  514. The format of the file is the same as the version node without
  515. scope and node name. See @ref{VERSION} for more information.
  516. @ifclear SingleFormat
  517. @cindex big-endian objects
  518. @cindex endianness
  519. @kindex -EB
  520. @item -EB
  521. Link big-endian objects. This affects the default output format.
  522. @cindex little-endian objects
  523. @kindex -EL
  524. @item -EL
  525. Link little-endian objects. This affects the default output format.
  526. @end ifclear
  527. @kindex -f @var{name}
  528. @kindex --auxiliary=@var{name}
  529. @item -f @var{name}
  530. @itemx --auxiliary=@var{name}
  531. When creating an ELF shared object, set the internal DT_AUXILIARY field
  532. to the specified name. This tells the dynamic linker that the symbol
  533. table of the shared object should be used as an auxiliary filter on the
  534. symbol table of the shared object @var{name}.
  535. If you later link a program against this filter object, then, when you
  536. run the program, the dynamic linker will see the DT_AUXILIARY field. If
  537. the dynamic linker resolves any symbols from the filter object, it will
  538. first check whether there is a definition in the shared object
  539. @var{name}. If there is one, it will be used instead of the definition
  540. in the filter object. The shared object @var{name} need not exist.
  541. Thus the shared object @var{name} may be used to provide an alternative
  542. implementation of certain functions, perhaps for debugging or for
  543. machine-specific performance.
  544. This option may be specified more than once. The DT_AUXILIARY entries
  545. will be created in the order in which they appear on the command line.
  546. @kindex -F @var{name}
  547. @kindex --filter=@var{name}
  548. @item -F @var{name}
  549. @itemx --filter=@var{name}
  550. When creating an ELF shared object, set the internal DT_FILTER field to
  551. the specified name. This tells the dynamic linker that the symbol table
  552. of the shared object which is being created should be used as a filter
  553. on the symbol table of the shared object @var{name}.
  554. If you later link a program against this filter object, then, when you
  555. run the program, the dynamic linker will see the DT_FILTER field. The
  556. dynamic linker will resolve symbols according to the symbol table of the
  557. filter object as usual, but it will actually link to the definitions
  558. found in the shared object @var{name}. Thus the filter object can be
  559. used to select a subset of the symbols provided by the object
  560. @var{name}.
  561. Some older linkers used the @option{-F} option throughout a compilation
  562. toolchain for specifying object-file format for both input and output
  563. object files.
  564. @ifclear SingleFormat
  565. The @sc{gnu} linker uses other mechanisms for this purpose: the
  566. @option{-b}, @option{--format}, @option{--oformat} options, the
  567. @code{TARGET} command in linker scripts, and the @code{GNUTARGET}
  568. environment variable.
  569. @end ifclear
  570. The @sc{gnu} linker will ignore the @option{-F} option when not
  571. creating an ELF shared object.
  572. @cindex finalization function
  573. @kindex -fini=@var{name}
  574. @item -fini=@var{name}
  575. When creating an ELF executable or shared object, call NAME when the
  576. executable or shared object is unloaded, by setting DT_FINI to the
  577. address of the function. By default, the linker uses @code{_fini} as
  578. the function to call.
  579. @kindex -g
  580. @item -g
  581. Ignored. Provided for compatibility with other tools.
  582. @kindex -G @var{value}
  583. @kindex --gpsize=@var{value}
  584. @cindex object size
  585. @item -G @var{value}
  586. @itemx --gpsize=@var{value}
  587. Set the maximum size of objects to be optimized using the GP register to
  588. @var{size}. This is only meaningful for object file formats such as
  589. MIPS ELF that support putting large and small objects into different
  590. sections. This is ignored for other object file formats.
  591. @cindex runtime library name
  592. @kindex -h @var{name}
  593. @kindex -soname=@var{name}
  594. @item -h @var{name}
  595. @itemx -soname=@var{name}
  596. When creating an ELF shared object, set the internal DT_SONAME field to
  597. the specified name. When an executable is linked with a shared object
  598. which has a DT_SONAME field, then when the executable is run the dynamic
  599. linker will attempt to load the shared object specified by the DT_SONAME
  600. field rather than using the file name given to the linker.
  601. @kindex -i
  602. @cindex incremental link
  603. @item -i
  604. Perform an incremental link (same as option @samp{-r}).
  605. @cindex initialization function
  606. @kindex -init=@var{name}
  607. @item -init=@var{name}
  608. When creating an ELF executable or shared object, call NAME when the
  609. executable or shared object is loaded, by setting DT_INIT to the address
  610. of the function. By default, the linker uses @code{_init} as the
  611. function to call.
  612. @cindex archive files, from cmd line
  613. @kindex -l @var{namespec}
  614. @kindex --library=@var{namespec}
  615. @item -l @var{namespec}
  616. @itemx --library=@var{namespec}
  617. Add the archive or object file specified by @var{namespec} to the
  618. list of files to link. This option may be used any number of times.
  619. If @var{namespec} is of the form @file{:@var{filename}}, @command{ld}
  620. will search the library path for a file called @var{filename}, otherwise it
  621. will search the library path for a file called @file{lib@var{namespec}.a}.
  622. On systems which support shared libraries, @command{ld} may also search for
  623. files other than @file{lib@var{namespec}.a}. Specifically, on ELF
  624. and SunOS systems, @command{ld} will search a directory for a library
  625. called @file{lib@var{namespec}.so} before searching for one called
  626. @file{lib@var{namespec}.a}. (By convention, a @code{.so} extension
  627. indicates a shared library.) Note that this behavior does not apply
  628. to @file{:@var{filename}}, which always specifies a file called
  629. @var{filename}.
  630. The linker will search an archive only once, at the location where it is
  631. specified on the command line. If the archive defines a symbol which
  632. was undefined in some object which appeared before the archive on the
  633. command line, the linker will include the appropriate file(s) from the
  634. archive. However, an undefined symbol in an object appearing later on
  635. the command line will not cause the linker to search the archive again.
  636. See the @option{-(} option for a way to force the linker to search
  637. archives multiple times.
  638. You may list the same archive multiple times on the command line.
  639. @ifset GENERIC
  640. This type of archive searching is standard for Unix linkers. However,
  641. if you are using @command{ld} on AIX, note that it is different from the
  642. behaviour of the AIX linker.
  643. @end ifset
  644. @cindex search directory, from cmd line
  645. @kindex -L @var{dir}
  646. @kindex --library-path=@var{dir}
  647. @item -L @var{searchdir}
  648. @itemx --library-path=@var{searchdir}
  649. Add path @var{searchdir} to the list of paths that @command{ld} will search
  650. for archive libraries and @command{ld} control scripts. You may use this
  651. option any number of times. The directories are searched in the order
  652. in which they are specified on the command line. Directories specified
  653. on the command line are searched before the default directories. All
  654. @option{-L} options apply to all @option{-l} options, regardless of the
  655. order in which the options appear. @option{-L} options do not affect
  656. how @command{ld} searches for a linker script unless @option{-T}
  657. option is specified.
  658. If @var{searchdir} begins with @code{=} or @code{$SYSROOT}, then this
  659. prefix will be replaced by the @dfn{sysroot prefix}, controlled by the
  660. @samp{--sysroot} option, or specified when the linker is configured.
  661. @ifset UsesEnvVars
  662. The default set of paths searched (without being specified with
  663. @samp{-L}) depends on which emulation mode @command{ld} is using, and in
  664. some cases also on how it was configured. @xref{Environment}.
  665. @end ifset
  666. The paths can also be specified in a link script with the
  667. @code{SEARCH_DIR} command. Directories specified this way are searched
  668. at the point in which the linker script appears in the command line.
  669. @cindex emulation
  670. @kindex -m @var{emulation}
  671. @item -m @var{emulation}
  672. Emulate the @var{emulation} linker. You can list the available
  673. emulations with the @samp{--verbose} or @samp{-V} options.
  674. If the @samp{-m} option is not used, the emulation is taken from the
  675. @code{LDEMULATION} environment variable, if that is defined.
  676. Otherwise, the default emulation depends upon how the linker was
  677. configured.
  678. @cindex link map
  679. @kindex -M
  680. @kindex --print-map
  681. @item -M
  682. @itemx --print-map
  683. Print a link map to the standard output. A link map provides
  684. information about the link, including the following:
  685. @itemize @bullet
  686. @item
  687. Where object files are mapped into memory.
  688. @item
  689. How common symbols are allocated.
  690. @item
  691. All archive members included in the link, with a mention of the symbol
  692. which caused the archive member to be brought in.
  693. @item
  694. The values assigned to symbols.
  695. Note - symbols whose values are computed by an expression which
  696. involves a reference to a previous value of the same symbol may not
  697. have correct result displayed in the link map. This is because the
  698. linker discards intermediate results and only retains the final value
  699. of an expression. Under such circumstances the linker will display
  700. the final value enclosed by square brackets. Thus for example a
  701. linker script containing:
  702. @smallexample
  703. foo = 1
  704. foo = foo * 4
  705. foo = foo + 8
  706. @end smallexample
  707. will produce the following output in the link map if the @option{-M}
  708. option is used:
  709. @smallexample
  710. 0x00000001 foo = 0x1
  711. [0x0000000c] foo = (foo * 0x4)
  712. [0x0000000c] foo = (foo + 0x8)
  713. @end smallexample
  714. See @ref{Expressions} for more information about expressions in linker
  715. scripts.
  716. @item
  717. How GNU properties are merged.
  718. When the linker merges input .note.gnu.property sections into one output
  719. .note.gnu.property section, some properties are removed or updated.
  720. These actions are reported in the link map. For example:
  721. @smallexample
  722. Removed property 0xc0000002 to merge foo.o (0x1) and bar.o (not found)
  723. @end smallexample
  724. This indicates that property 0xc0000002 is removed from output when
  725. merging properties in @file{foo.o}, whose property 0xc0000002 value
  726. is 0x1, and @file{bar.o}, which doesn't have property 0xc0000002.
  727. @smallexample
  728. Updated property 0xc0010001 (0x1) to merge foo.o (0x1) and bar.o (0x1)
  729. @end smallexample
  730. This indicates that property 0xc0010001 value is updated to 0x1 in output
  731. when merging properties in @file{foo.o}, whose 0xc0010001 property value
  732. is 0x1, and @file{bar.o}, whose 0xc0010001 property value is 0x1.
  733. @end itemize
  734. @cindex link map discarded
  735. @kindex --print-map-discarded
  736. @kindex --no-print-map-discarded
  737. @item --print-map-discarded
  738. @itemx --no-print-map-discarded
  739. Print (or do not print) the list of discarded and garbage collected sections
  740. in the link map. Enabled by default.
  741. @kindex -n
  742. @cindex read-only text
  743. @cindex NMAGIC
  744. @kindex --nmagic
  745. @item -n
  746. @itemx --nmagic
  747. Turn off page alignment of sections, and disable linking against shared
  748. libraries. If the output format supports Unix style magic numbers,
  749. mark the output as @code{NMAGIC}.
  750. @kindex -N
  751. @kindex --omagic
  752. @cindex read/write from cmd line
  753. @cindex OMAGIC
  754. @item -N
  755. @itemx --omagic
  756. Set the text and data sections to be readable and writable. Also, do
  757. not page-align the data segment, and disable linking against shared
  758. libraries. If the output format supports Unix style magic numbers,
  759. mark the output as @code{OMAGIC}. Note: Although a writable text section
  760. is allowed for PE-COFF targets, it does not conform to the format
  761. specification published by Microsoft.
  762. @kindex --no-omagic
  763. @cindex OMAGIC
  764. @item --no-omagic
  765. This option negates most of the effects of the @option{-N} option. It
  766. sets the text section to be read-only, and forces the data segment to
  767. be page-aligned. Note - this option does not enable linking against
  768. shared libraries. Use @option{-Bdynamic} for this.
  769. @kindex -o @var{output}
  770. @kindex --output=@var{output}
  771. @cindex naming the output file
  772. @item -o @var{output}
  773. @itemx --output=@var{output}
  774. Use @var{output} as the name for the program produced by @command{ld}; if this
  775. option is not specified, the name @file{a.out} is used by default. The
  776. script command @code{OUTPUT} can also specify the output file name.
  777. @kindex --dependency-file=@var{depfile}
  778. @cindex dependency file
  779. @item --dependency-file=@var{depfile}
  780. Write a @dfn{dependency file} to @var{depfile}. This file contains a rule
  781. suitable for @code{make} describing the output file and all the input files
  782. that were read to produce it. The output is similar to the compiler's
  783. output with @samp{-M -MP} (@pxref{Preprocessor Options,, Options
  784. Controlling the Preprocessor, gcc.info, Using the GNU Compiler
  785. Collection}). Note that there is no option like the compiler's @samp{-MM},
  786. to exclude ``system files'' (which is not a well-specified concept in the
  787. linker, unlike ``system headers'' in the compiler). So the output from
  788. @samp{--dependency-file} is always specific to the exact state of the
  789. installation where it was produced, and should not be copied into
  790. distributed makefiles without careful editing.
  791. @kindex -O @var{level}
  792. @cindex generating optimized output
  793. @item -O @var{level}
  794. If @var{level} is a numeric values greater than zero @command{ld} optimizes
  795. the output. This might take significantly longer and therefore probably
  796. should only be enabled for the final binary. At the moment this
  797. option only affects ELF shared library generation. Future releases of
  798. the linker may make more use of this option. Also currently there is
  799. no difference in the linker's behaviour for different non-zero values
  800. of this option. Again this may change with future releases.
  801. @kindex -plugin @var{name}
  802. @item -plugin @var{name}
  803. Involve a plugin in the linking process. The @var{name} parameter is
  804. the absolute filename of the plugin. Usually this parameter is
  805. automatically added by the complier, when using link time
  806. optimization, but users can also add their own plugins if they so
  807. wish.
  808. Note that the location of the compiler originated plugins is different
  809. from the place where the @command{ar}, @command{nm} and
  810. @command{ranlib} programs search for their plugins. In order for
  811. those commands to make use of a compiler based plugin it must first be
  812. copied into the @file{$@{libdir@}/bfd-plugins} directory. All gcc
  813. based linker plugins are backward compatible, so it is sufficient to
  814. just copy in the newest one.
  815. @kindex --push-state
  816. @cindex push state governing input file handling
  817. @item --push-state
  818. The @option{--push-state} allows one to preserve the current state of the
  819. flags which govern the input file handling so that they can all be
  820. restored with one corresponding @option{--pop-state} option.
  821. The option which are covered are: @option{-Bdynamic}, @option{-Bstatic},
  822. @option{-dn}, @option{-dy}, @option{-call_shared}, @option{-non_shared},
  823. @option{-static}, @option{-N}, @option{-n}, @option{--whole-archive},
  824. @option{--no-whole-archive}, @option{-r}, @option{-Ur},
  825. @option{--copy-dt-needed-entries}, @option{--no-copy-dt-needed-entries},
  826. @option{--as-needed}, @option{--no-as-needed}, and @option{-a}.
  827. One target for this option are specifications for @file{pkg-config}. When
  828. used with the @option{--libs} option all possibly needed libraries are
  829. listed and then possibly linked with all the time. It is better to return
  830. something as follows:
  831. @smallexample
  832. -Wl,--push-state,--as-needed -libone -libtwo -Wl,--pop-state
  833. @end smallexample
  834. @kindex --pop-state
  835. @cindex pop state governing input file handling
  836. @item --pop-state
  837. Undoes the effect of --push-state, restores the previous values of the
  838. flags governing input file handling.
  839. @kindex -q
  840. @kindex --emit-relocs
  841. @cindex retain relocations in final executable
  842. @item -q
  843. @itemx --emit-relocs
  844. Leave relocation sections and contents in fully linked executables.
  845. Post link analysis and optimization tools may need this information in
  846. order to perform correct modifications of executables. This results
  847. in larger executables.
  848. This option is currently only supported on ELF platforms.
  849. @kindex --force-dynamic
  850. @cindex forcing the creation of dynamic sections
  851. @item --force-dynamic
  852. Force the output file to have dynamic sections. This option is specific
  853. to VxWorks targets.
  854. @cindex partial link
  855. @cindex relocatable output
  856. @kindex -r
  857. @kindex --relocatable
  858. @item -r
  859. @itemx --relocatable
  860. Generate relocatable output---i.e., generate an output file that can in
  861. turn serve as input to @command{ld}. This is often called @dfn{partial
  862. linking}. As a side effect, in environments that support standard Unix
  863. magic numbers, this option also sets the output file's magic number to
  864. @code{OMAGIC}.
  865. @c ; see @option{-N}.
  866. If this option is not specified, an absolute file is produced. When
  867. linking C++ programs, this option @emph{will not} resolve references to
  868. constructors; to do that, use @samp{-Ur}.
  869. When an input file does not have the same format as the output file,
  870. partial linking is only supported if that input file does not contain any
  871. relocations. Different output formats can have further restrictions; for
  872. example some @code{a.out}-based formats do not support partial linking
  873. with input files in other formats at all.
  874. This option does the same thing as @samp{-i}.
  875. @kindex -R @var{file}
  876. @kindex --just-symbols=@var{file}
  877. @cindex symbol-only input
  878. @item -R @var{filename}
  879. @itemx --just-symbols=@var{filename}
  880. Read symbol names and their addresses from @var{filename}, but do not
  881. relocate it or include it in the output. This allows your output file
  882. to refer symbolically to absolute locations of memory defined in other
  883. programs. You may use this option more than once.
  884. For compatibility with other ELF linkers, if the @option{-R} option is
  885. followed by a directory name, rather than a file name, it is treated as
  886. the @option{-rpath} option.
  887. @kindex -s
  888. @kindex --strip-all
  889. @cindex strip all symbols
  890. @item -s
  891. @itemx --strip-all
  892. Omit all symbol information from the output file.
  893. @kindex -S
  894. @kindex --strip-debug
  895. @cindex strip debugger symbols
  896. @item -S
  897. @itemx --strip-debug
  898. Omit debugger symbol information (but not all symbols) from the output file.
  899. @kindex --strip-discarded
  900. @kindex --no-strip-discarded
  901. @item --strip-discarded
  902. @itemx --no-strip-discarded
  903. Omit (or do not omit) global symbols defined in discarded sections.
  904. Enabled by default.
  905. @kindex -t
  906. @kindex --trace
  907. @cindex input files, displaying
  908. @item -t
  909. @itemx --trace
  910. Print the names of the input files as @command{ld} processes them. If
  911. @samp{-t} is given twice then members within archives are also printed.
  912. @samp{-t} output is useful to generate a list of all the object files
  913. and scripts involved in linking, for example, when packaging files for
  914. a linker bug report.
  915. @kindex -T @var{script}
  916. @kindex --script=@var{script}
  917. @cindex script files
  918. @item -T @var{scriptfile}
  919. @itemx --script=@var{scriptfile}
  920. Use @var{scriptfile} as the linker script. This script replaces
  921. @command{ld}'s default linker script (rather than adding to it), so
  922. @var{commandfile} must specify everything necessary to describe the
  923. output file. @xref{Scripts}. If @var{scriptfile} does not exist in
  924. the current directory, @code{ld} looks for it in the directories
  925. specified by any preceding @samp{-L} options. Multiple @samp{-T}
  926. options accumulate.
  927. @kindex -dT @var{script}
  928. @kindex --default-script=@var{script}
  929. @cindex script files
  930. @item -dT @var{scriptfile}
  931. @itemx --default-script=@var{scriptfile}
  932. Use @var{scriptfile} as the default linker script. @xref{Scripts}.
  933. This option is similar to the @option{--script} option except that
  934. processing of the script is delayed until after the rest of the
  935. command line has been processed. This allows options placed after the
  936. @option{--default-script} option on the command line to affect the
  937. behaviour of the linker script, which can be important when the linker
  938. command line cannot be directly controlled by the user. (eg because
  939. the command line is being constructed by another tool, such as
  940. @samp{gcc}).
  941. @kindex -u @var{symbol}
  942. @kindex --undefined=@var{symbol}
  943. @cindex undefined symbol
  944. @item -u @var{symbol}
  945. @itemx --undefined=@var{symbol}
  946. Force @var{symbol} to be entered in the output file as an undefined
  947. symbol. Doing this may, for example, trigger linking of additional
  948. modules from standard libraries. @samp{-u} may be repeated with
  949. different option arguments to enter additional undefined symbols. This
  950. option is equivalent to the @code{EXTERN} linker script command.
  951. If this option is being used to force additional modules to be pulled
  952. into the link, and if it is an error for the symbol to remain
  953. undefined, then the option @option{--require-defined} should be used
  954. instead.
  955. @kindex --require-defined=@var{symbol}
  956. @cindex symbols, require defined
  957. @cindex defined symbol
  958. @item --require-defined=@var{symbol}
  959. Require that @var{symbol} is defined in the output file. This option
  960. is the same as option @option{--undefined} except that if @var{symbol}
  961. is not defined in the output file then the linker will issue an error
  962. and exit. The same effect can be achieved in a linker script by using
  963. @code{EXTERN}, @code{ASSERT} and @code{DEFINED} together. This option
  964. can be used multiple times to require additional symbols.
  965. @kindex -Ur
  966. @cindex constructors
  967. @item -Ur
  968. For anything other than C++ programs, this option is equivalent to
  969. @samp{-r}: it generates relocatable output---i.e., an output file that can in
  970. turn serve as input to @command{ld}. When linking C++ programs, @samp{-Ur}
  971. @emph{does} resolve references to constructors, unlike @samp{-r}.
  972. It does not work to use @samp{-Ur} on files that were themselves linked
  973. with @samp{-Ur}; once the constructor table has been built, it cannot
  974. be added to. Use @samp{-Ur} only for the last partial link, and
  975. @samp{-r} for the others.
  976. @kindex --orphan-handling=@var{MODE}
  977. @cindex orphan sections
  978. @cindex sections, orphan
  979. @item --orphan-handling=@var{MODE}
  980. Control how orphan sections are handled. An orphan section is one not
  981. specifically mentioned in a linker script. @xref{Orphan Sections}.
  982. @var{MODE} can have any of the following values:
  983. @table @code
  984. @item place
  985. Orphan sections are placed into a suitable output section following
  986. the strategy described in @ref{Orphan Sections}. The option
  987. @samp{--unique} also affects how sections are placed.
  988. @item discard
  989. All orphan sections are discarded, by placing them in the
  990. @samp{/DISCARD/} section (@pxref{Output Section Discarding}).
  991. @item warn
  992. The linker will place the orphan section as for @code{place} and also
  993. issue a warning.
  994. @item error
  995. The linker will exit with an error if any orphan section is found.
  996. @end table
  997. The default if @samp{--orphan-handling} is not given is @code{place}.
  998. @kindex --unique[=@var{SECTION}]
  999. @item --unique[=@var{SECTION}]
  1000. Creates a separate output section for every input section matching
  1001. @var{SECTION}, or if the optional wildcard @var{SECTION} argument is
  1002. missing, for every orphan input section. An orphan section is one not
  1003. specifically mentioned in a linker script. You may use this option
  1004. multiple times on the command line; It prevents the normal merging of
  1005. input sections with the same name, overriding output section assignments
  1006. in a linker script.
  1007. @kindex -v
  1008. @kindex -V
  1009. @kindex --version
  1010. @cindex version
  1011. @item -v
  1012. @itemx --version
  1013. @itemx -V
  1014. Display the version number for @command{ld}. The @option{-V} option also
  1015. lists the supported emulations.
  1016. @kindex -x
  1017. @kindex --discard-all
  1018. @cindex deleting local symbols
  1019. @item -x
  1020. @itemx --discard-all
  1021. Delete all local symbols.
  1022. @kindex -X
  1023. @kindex --discard-locals
  1024. @cindex local symbols, deleting
  1025. @item -X
  1026. @itemx --discard-locals
  1027. Delete all temporary local symbols. (These symbols start with
  1028. system-specific local label prefixes, typically @samp{.L} for ELF systems
  1029. or @samp{L} for traditional a.out systems.)
  1030. @kindex -y @var{symbol}
  1031. @kindex --trace-symbol=@var{symbol}
  1032. @cindex symbol tracing
  1033. @item -y @var{symbol}
  1034. @itemx --trace-symbol=@var{symbol}
  1035. Print the name of each linked file in which @var{symbol} appears. This
  1036. option may be given any number of times. On many systems it is necessary
  1037. to prepend an underscore.
  1038. This option is useful when you have an undefined symbol in your link but
  1039. don't know where the reference is coming from.
  1040. @kindex -Y @var{path}
  1041. @item -Y @var{path}
  1042. Add @var{path} to the default library search path. This option exists
  1043. for Solaris compatibility.
  1044. @kindex -z @var{keyword}
  1045. @item -z @var{keyword}
  1046. The recognized keywords are:
  1047. @table @samp
  1048. @item bndplt
  1049. Always generate BND prefix in PLT entries. Supported for Linux/x86_64.
  1050. @item call-nop=prefix-addr
  1051. @itemx call-nop=suffix-nop
  1052. @itemx call-nop=prefix-@var{byte}
  1053. @itemx call-nop=suffix-@var{byte}
  1054. Specify the 1-byte @code{NOP} padding when transforming indirect call
  1055. to a locally defined function, foo, via its GOT slot.
  1056. @option{call-nop=prefix-addr} generates @code{0x67 call foo}.
  1057. @option{call-nop=suffix-nop} generates @code{call foo 0x90}.
  1058. @option{call-nop=prefix-@var{byte}} generates @code{@var{byte} call foo}.
  1059. @option{call-nop=suffix-@var{byte}} generates @code{call foo @var{byte}}.
  1060. Supported for i386 and x86_64.
  1061. @item cet-report=none
  1062. @itemx cet-report=warning
  1063. @itemx cet-report=error
  1064. Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_IBT and
  1065. GNU_PROPERTY_X86_FEATURE_1_SHSTK properties in input .note.gnu.property
  1066. section. @option{cet-report=none}, which is the default, will make the
  1067. linker not report missing properties in input files.
  1068. @option{cet-report=warning} will make the linker issue a warning for
  1069. missing properties in input files. @option{cet-report=error} will make
  1070. the linker issue an error for missing properties in input files.
  1071. Note that @option{ibt} will turn off the missing
  1072. GNU_PROPERTY_X86_FEATURE_1_IBT property report and @option{shstk} will
  1073. turn off the missing GNU_PROPERTY_X86_FEATURE_1_SHSTK property report.
  1074. Supported for Linux/i386 and Linux/x86_64.
  1075. @item combreloc
  1076. @itemx nocombreloc
  1077. Combine multiple dynamic relocation sections and sort to improve
  1078. dynamic symbol lookup caching. Do not do this if @samp{nocombreloc}.
  1079. @item common
  1080. @itemx nocommon
  1081. Generate common symbols with STT_COMMON type during a relocatable
  1082. link. Use STT_OBJECT type if @samp{nocommon}.
  1083. @item common-page-size=@var{value}
  1084. Set the page size most commonly used to @var{value}. Memory image
  1085. layout will be optimized to minimize memory pages if the system is
  1086. using pages of this size.
  1087. @item defs
  1088. Report unresolved symbol references from regular object files. This
  1089. is done even if the linker is creating a non-symbolic shared library.
  1090. This option is the inverse of @samp{-z undefs}.
  1091. @item dynamic-undefined-weak
  1092. @itemx nodynamic-undefined-weak
  1093. Make undefined weak symbols dynamic when building a dynamic object,
  1094. if they are referenced from a regular object file and not forced local
  1095. by symbol visibility or versioning. Do not make them dynamic if
  1096. @samp{nodynamic-undefined-weak}. If neither option is given, a target
  1097. may default to either option being in force, or make some other
  1098. selection of undefined weak symbols dynamic. Not all targets support
  1099. these options.
  1100. @item execstack
  1101. Marks the object as requiring executable stack.
  1102. @item global
  1103. This option is only meaningful when building a shared object. It makes
  1104. the symbols defined by this shared object available for symbol resolution
  1105. of subsequently loaded libraries.
  1106. @item globalaudit
  1107. This option is only meaningful when building a dynamic executable.
  1108. This option marks the executable as requiring global auditing by
  1109. setting the @code{DF_1_GLOBAUDIT} bit in the @code{DT_FLAGS_1} dynamic
  1110. tag. Global auditing requires that any auditing library defined via
  1111. the @option{--depaudit} or @option{-P} command-line options be run for
  1112. all dynamic objects loaded by the application.
  1113. @item ibtplt
  1114. Generate Intel Indirect Branch Tracking (IBT) enabled PLT entries.
  1115. Supported for Linux/i386 and Linux/x86_64.
  1116. @item ibt
  1117. Generate GNU_PROPERTY_X86_FEATURE_1_IBT in .note.gnu.property section
  1118. to indicate compatibility with IBT. This also implies @option{ibtplt}.
  1119. Supported for Linux/i386 and Linux/x86_64.
  1120. @item indirect-extern-access
  1121. @itemx noindirect-extern-access
  1122. Generate GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS in
  1123. .note.gnu.property section to indicate that object file requires
  1124. canonical function pointers and cannot be used with copy relocation.
  1125. This option also implies @option{noextern-protected-data} and
  1126. @option{nocopyreloc}. Supported for i386 and x86-64.
  1127. @option{noindirect-extern-access} removes
  1128. GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS from .note.gnu.property
  1129. section.
  1130. @item initfirst
  1131. This option is only meaningful when building a shared object.
  1132. It marks the object so that its runtime initialization will occur
  1133. before the runtime initialization of any other objects brought into
  1134. the process at the same time. Similarly the runtime finalization of
  1135. the object will occur after the runtime finalization of any other
  1136. objects.
  1137. @item interpose
  1138. Specify that the dynamic loader should modify its symbol search order
  1139. so that symbols in this shared library interpose all other shared
  1140. libraries not so marked.
  1141. @item unique
  1142. @itemx nounique
  1143. When generating a shared library or other dynamically loadable ELF
  1144. object mark it as one that should (by default) only ever be loaded once,
  1145. and only in the main namespace (when using @code{dlmopen}). This is
  1146. primarily used to mark fundamental libraries such as libc, libpthread et
  1147. al which do not usually function correctly unless they are the sole instances
  1148. of themselves. This behaviour can be overridden by the @code{dlmopen} caller
  1149. and does not apply to certain loading mechanisms (such as audit libraries).
  1150. @item lam-u48
  1151. Generate GNU_PROPERTY_X86_FEATURE_1_LAM_U48 in .note.gnu.property section
  1152. to indicate compatibility with Intel LAM_U48. Supported for Linux/x86_64.
  1153. @item lam-u57
  1154. Generate GNU_PROPERTY_X86_FEATURE_1_LAM_U57 in .note.gnu.property section
  1155. to indicate compatibility with Intel LAM_U57. Supported for Linux/x86_64.
  1156. @item lam-u48-report=none
  1157. @itemx lam-u48-report=warning
  1158. @itemx lam-u48-report=error
  1159. Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U48
  1160. property in input .note.gnu.property section.
  1161. @option{lam-u48-report=none}, which is the default, will make the
  1162. linker not report missing properties in input files.
  1163. @option{lam-u48-report=warning} will make the linker issue a warning for
  1164. missing properties in input files. @option{lam-u48-report=error} will
  1165. make the linker issue an error for missing properties in input files.
  1166. Supported for Linux/x86_64.
  1167. @item lam-u57-report=none
  1168. @itemx lam-u57-report=warning
  1169. @itemx lam-u57-report=error
  1170. Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U57
  1171. property in input .note.gnu.property section.
  1172. @option{lam-u57-report=none}, which is the default, will make the
  1173. linker not report missing properties in input files.
  1174. @option{lam-u57-report=warning} will make the linker issue a warning for
  1175. missing properties in input files. @option{lam-u57-report=error} will
  1176. make the linker issue an error for missing properties in input files.
  1177. Supported for Linux/x86_64.
  1178. @item lam-report=none
  1179. @itemx lam-report=warning
  1180. @itemx lam-report=error
  1181. Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
  1182. GNU_PROPERTY_X86_FEATURE_1_LAM_U57 properties in input .note.gnu.property
  1183. section. @option{lam-report=none}, which is the default, will make the
  1184. linker not report missing properties in input files.
  1185. @option{lam-report=warning} will make the linker issue a warning for
  1186. missing properties in input files. @option{lam-report=error} will make
  1187. the linker issue an error for missing properties in input files.
  1188. Supported for Linux/x86_64.
  1189. @item lazy
  1190. When generating an executable or shared library, mark it to tell the
  1191. dynamic linker to defer function call resolution to the point when
  1192. the function is called (lazy binding), rather than at load time.
  1193. Lazy binding is the default.
  1194. @item loadfltr
  1195. Specify that the object's filters be processed immediately at runtime.
  1196. @item max-page-size=@var{value}
  1197. Set the maximum memory page size supported to @var{value}.
  1198. @item muldefs
  1199. Allow multiple definitions.
  1200. @item nocopyreloc
  1201. Disable linker generated .dynbss variables used in place of variables
  1202. defined in shared libraries. May result in dynamic text relocations.
  1203. @item nodefaultlib
  1204. Specify that the dynamic loader search for dependencies of this object
  1205. should ignore any default library search paths.
  1206. @item nodelete
  1207. Specify that the object shouldn't be unloaded at runtime.
  1208. @item nodlopen
  1209. Specify that the object is not available to @code{dlopen}.
  1210. @item nodump
  1211. Specify that the object can not be dumped by @code{dldump}.
  1212. @item noexecstack
  1213. Marks the object as not requiring executable stack.
  1214. @item noextern-protected-data
  1215. Don't treat protected data symbols as external when building a shared
  1216. library. This option overrides the linker backend default. It can be
  1217. used to work around incorrect relocations against protected data symbols
  1218. generated by compiler. Updates on protected data symbols by another
  1219. module aren't visible to the resulting shared library. Supported for
  1220. i386 and x86-64.
  1221. @item noreloc-overflow
  1222. Disable relocation overflow check. This can be used to disable
  1223. relocation overflow check if there will be no dynamic relocation
  1224. overflow at run-time. Supported for x86_64.
  1225. @item now
  1226. When generating an executable or shared library, mark it to tell the
  1227. dynamic linker to resolve all symbols when the program is started, or
  1228. when the shared library is loaded by dlopen, instead of deferring
  1229. function call resolution to the point when the function is first
  1230. called.
  1231. @item origin
  1232. Specify that the object requires @samp{$ORIGIN} handling in paths.
  1233. @item pack-relative-relocs
  1234. @itemx nopack-relative-relocs
  1235. Generate compact relative relocation in position-independent executable
  1236. and shared library. It adds @code{DT_RELR}, @code{DT_RELRSZ} and
  1237. @code{DT_RELRENT} entries to the dynamic section. It is ignored when
  1238. building position-dependent executable and relocatable output.
  1239. @option{nopack-relative-relocs} is the default, which disables compact
  1240. relative relocation. When linked against the GNU C Library, a
  1241. GLIBC_ABI_DT_RELR symbol version dependency on the shared C Library is
  1242. added to the output. Supported for i386 and x86-64.
  1243. @item relro
  1244. @itemx norelro
  1245. Create an ELF @code{PT_GNU_RELRO} segment header in the object. This
  1246. specifies a memory segment that should be made read-only after
  1247. relocation, if supported. Specifying @samp{common-page-size} smaller
  1248. than the system page size will render this protection ineffective.
  1249. Don't create an ELF @code{PT_GNU_RELRO} segment if @samp{norelro}.
  1250. @item report-relative-reloc
  1251. Report dynamic relative relocations generated by linker. Supported for
  1252. Linux/i386 and Linux/x86_64.
  1253. @item separate-code
  1254. @itemx noseparate-code
  1255. Create separate code @code{PT_LOAD} segment header in the object. This
  1256. specifies a memory segment that should contain only instructions and must
  1257. be in wholly disjoint pages from any other data. Don't create separate
  1258. code @code{PT_LOAD} segment if @samp{noseparate-code} is used.
  1259. @item shstk
  1260. Generate GNU_PROPERTY_X86_FEATURE_1_SHSTK in .note.gnu.property section
  1261. to indicate compatibility with Intel Shadow Stack. Supported for
  1262. Linux/i386 and Linux/x86_64.
  1263. @item stack-size=@var{value}
  1264. Specify a stack size for an ELF @code{PT_GNU_STACK} segment.
  1265. Specifying zero will override any default non-zero sized
  1266. @code{PT_GNU_STACK} segment creation.
  1267. @item start-stop-gc
  1268. @itemx nostart-stop-gc
  1269. @cindex start-stop-gc
  1270. When @samp{--gc-sections} is in effect, a reference from a retained
  1271. section to @code{__start_SECNAME} or @code{__stop_SECNAME} causes all
  1272. input sections named @code{SECNAME} to also be retained, if
  1273. @code{SECNAME} is representable as a C identifier and either
  1274. @code{__start_SECNAME} or @code{__stop_SECNAME} is synthesized by the
  1275. linker. @samp{-z start-stop-gc} disables this effect, allowing
  1276. sections to be garbage collected as if the special synthesized symbols
  1277. were not defined. @samp{-z start-stop-gc} has no effect on a
  1278. definition of @code{__start_SECNAME} or @code{__stop_SECNAME} in an
  1279. object file or linker script. Such a definition will prevent the
  1280. linker providing a synthesized @code{__start_SECNAME} or
  1281. @code{__stop_SECNAME} respectively, and therefore the special
  1282. treatment by garbage collection for those references.
  1283. @item start-stop-visibility=@var{value}
  1284. @cindex visibility
  1285. @cindex ELF symbol visibility
  1286. Specify the ELF symbol visibility for synthesized
  1287. @code{__start_SECNAME} and @code{__stop_SECNAME} symbols (@pxref{Input
  1288. Section Example}). @var{value} must be exactly @samp{default},
  1289. @samp{internal}, @samp{hidden}, or @samp{protected}. If no @samp{-z
  1290. start-stop-visibility} option is given, @samp{protected} is used for
  1291. compatibility with historical practice. However, it's highly
  1292. recommended to use @samp{-z start-stop-visibility=hidden} in new
  1293. programs and shared libraries so that these symbols are not exported
  1294. between shared objects, which is not usually what's intended.
  1295. @item text
  1296. @itemx notext
  1297. @itemx textoff
  1298. Report an error if DT_TEXTREL is set, i.e., if the position-independent
  1299. or shared object has dynamic relocations in read-only sections. Don't
  1300. report an error if @samp{notext} or @samp{textoff}.
  1301. @item undefs
  1302. Do not report unresolved symbol references from regular object files,
  1303. either when creating an executable, or when creating a shared library.
  1304. This option is the inverse of @samp{-z defs}.
  1305. @item unique-symbol
  1306. @itemx nounique-symbol
  1307. Avoid duplicated local symbol names in the symbol string table. Append
  1308. ".@code{number}" to duplicated local symbol names if @samp{unique-symbol}
  1309. is used. @option{nounique-symbol} is the default.
  1310. @item x86-64-baseline
  1311. @item x86-64-v2
  1312. @item x86-64-v3
  1313. @itemx x86-64-v4
  1314. Specify the x86-64 ISA level needed in .note.gnu.property section.
  1315. @option{x86-64-baseline} generates @code{GNU_PROPERTY_X86_ISA_1_BASELINE}.
  1316. @option{x86-64-v2} generates @code{GNU_PROPERTY_X86_ISA_1_V2}.
  1317. @option{x86-64-v3} generates @code{GNU_PROPERTY_X86_ISA_1_V3}.
  1318. @option{x86-64-v4} generates @code{GNU_PROPERTY_X86_ISA_1_V4}.
  1319. Supported for Linux/i386 and Linux/x86_64.
  1320. @end table
  1321. Other keywords are ignored for Solaris compatibility.
  1322. @kindex -(
  1323. @cindex groups of archives
  1324. @item -( @var{archives} -)
  1325. @itemx --start-group @var{archives} --end-group
  1326. The @var{archives} should be a list of archive files. They may be
  1327. either explicit file names, or @samp{-l} options.
  1328. The specified archives are searched repeatedly until no new undefined
  1329. references are created. Normally, an archive is searched only once in
  1330. the order that it is specified on the command line. If a symbol in that
  1331. archive is needed to resolve an undefined symbol referred to by an
  1332. object in an archive that appears later on the command line, the linker
  1333. would not be able to resolve that reference. By grouping the archives,
  1334. they will all be searched repeatedly until all possible references are
  1335. resolved.
  1336. Using this option has a significant performance cost. It is best to use
  1337. it only when there are unavoidable circular references between two or
  1338. more archives.
  1339. @kindex --accept-unknown-input-arch
  1340. @kindex --no-accept-unknown-input-arch
  1341. @item --accept-unknown-input-arch
  1342. @itemx --no-accept-unknown-input-arch
  1343. Tells the linker to accept input files whose architecture cannot be
  1344. recognised. The assumption is that the user knows what they are doing
  1345. and deliberately wants to link in these unknown input files. This was
  1346. the default behaviour of the linker, before release 2.14. The default
  1347. behaviour from release 2.14 onwards is to reject such input files, and
  1348. so the @samp{--accept-unknown-input-arch} option has been added to
  1349. restore the old behaviour.
  1350. @kindex --as-needed
  1351. @kindex --no-as-needed
  1352. @item --as-needed
  1353. @itemx --no-as-needed
  1354. This option affects ELF DT_NEEDED tags for dynamic libraries mentioned
  1355. on the command line after the @option{--as-needed} option. Normally
  1356. the linker will add a DT_NEEDED tag for each dynamic library mentioned
  1357. on the command line, regardless of whether the library is actually
  1358. needed or not. @option{--as-needed} causes a DT_NEEDED tag to only be
  1359. emitted for a library that @emph{at that point in the link} satisfies a
  1360. non-weak undefined symbol reference from a regular object file or, if
  1361. the library is not found in the DT_NEEDED lists of other needed libraries, a
  1362. non-weak undefined symbol reference from another needed dynamic library.
  1363. Object files or libraries appearing on the command line @emph{after}
  1364. the library in question do not affect whether the library is seen as
  1365. needed. This is similar to the rules for extraction of object files
  1366. from archives. @option{--no-as-needed} restores the default behaviour.
  1367. Note: On Linux based systems the @option{--as-needed} option also has
  1368. an affect on the behaviour of the @option{--rpath} and
  1369. @option{--rpath-link} options. See the description of
  1370. @option{--rpath-link} for more details.
  1371. @kindex --add-needed
  1372. @kindex --no-add-needed
  1373. @item --add-needed
  1374. @itemx --no-add-needed
  1375. These two options have been deprecated because of the similarity of
  1376. their names to the @option{--as-needed} and @option{--no-as-needed}
  1377. options. They have been replaced by @option{--copy-dt-needed-entries}
  1378. and @option{--no-copy-dt-needed-entries}.
  1379. @kindex -assert @var{keyword}
  1380. @item -assert @var{keyword}
  1381. This option is ignored for SunOS compatibility.
  1382. @kindex -Bdynamic
  1383. @kindex -dy
  1384. @kindex -call_shared
  1385. @item -Bdynamic
  1386. @itemx -dy
  1387. @itemx -call_shared
  1388. Link against dynamic libraries. This is only meaningful on platforms
  1389. for which shared libraries are supported. This option is normally the
  1390. default on such platforms. The different variants of this option are
  1391. for compatibility with various systems. You may use this option
  1392. multiple times on the command line: it affects library searching for
  1393. @option{-l} options which follow it.
  1394. @kindex -Bgroup
  1395. @item -Bgroup
  1396. Set the @code{DF_1_GROUP} flag in the @code{DT_FLAGS_1} entry in the dynamic
  1397. section. This causes the runtime linker to handle lookups in this
  1398. object and its dependencies to be performed only inside the group.
  1399. @option{--unresolved-symbols=report-all} is implied. This option is
  1400. only meaningful on ELF platforms which support shared libraries.
  1401. @kindex -Bstatic
  1402. @kindex -dn
  1403. @kindex -non_shared
  1404. @kindex -static
  1405. @item -Bstatic
  1406. @itemx -dn
  1407. @itemx -non_shared
  1408. @itemx -static
  1409. Do not link against shared libraries. This is only meaningful on
  1410. platforms for which shared libraries are supported. The different
  1411. variants of this option are for compatibility with various systems. You
  1412. may use this option multiple times on the command line: it affects
  1413. library searching for @option{-l} options which follow it. This
  1414. option also implies @option{--unresolved-symbols=report-all}. This
  1415. option can be used with @option{-shared}. Doing so means that a
  1416. shared library is being created but that all of the library's external
  1417. references must be resolved by pulling in entries from static
  1418. libraries.
  1419. @kindex -Bsymbolic
  1420. @item -Bsymbolic
  1421. When creating a shared library, bind references to global symbols to the
  1422. definition within the shared library, if any. Normally, it is possible
  1423. for a program linked against a shared library to override the definition
  1424. within the shared library. This option is only meaningful on ELF
  1425. platforms which support shared libraries.
  1426. @kindex -Bsymbolic-functions
  1427. @item -Bsymbolic-functions
  1428. When creating a shared library, bind references to global function
  1429. symbols to the definition within the shared library, if any.
  1430. This option is only meaningful on ELF platforms which support shared
  1431. libraries.
  1432. @kindex -Bno-symbolic
  1433. @item -Bno-symbolic
  1434. This option can cancel previously specified @samp{-Bsymbolic} and
  1435. @samp{-Bsymbolic-functions}.
  1436. @kindex --dynamic-list=@var{dynamic-list-file}
  1437. @item --dynamic-list=@var{dynamic-list-file}
  1438. Specify the name of a dynamic list file to the linker. This is
  1439. typically used when creating shared libraries to specify a list of
  1440. global symbols whose references shouldn't be bound to the definition
  1441. within the shared library, or creating dynamically linked executables
  1442. to specify a list of symbols which should be added to the symbol table
  1443. in the executable. This option is only meaningful on ELF platforms
  1444. which support shared libraries.
  1445. The format of the dynamic list is the same as the version node without
  1446. scope and node name. See @ref{VERSION} for more information.
  1447. @kindex --dynamic-list-data
  1448. @item --dynamic-list-data
  1449. Include all global data symbols to the dynamic list.
  1450. @kindex --dynamic-list-cpp-new
  1451. @item --dynamic-list-cpp-new
  1452. Provide the builtin dynamic list for C++ operator new and delete. It
  1453. is mainly useful for building shared libstdc++.
  1454. @kindex --dynamic-list-cpp-typeinfo
  1455. @item --dynamic-list-cpp-typeinfo
  1456. Provide the builtin dynamic list for C++ runtime type identification.
  1457. @kindex --check-sections
  1458. @kindex --no-check-sections
  1459. @item --check-sections
  1460. @itemx --no-check-sections
  1461. Asks the linker @emph{not} to check section addresses after they have
  1462. been assigned to see if there are any overlaps. Normally the linker will
  1463. perform this check, and if it finds any overlaps it will produce
  1464. suitable error messages. The linker does know about, and does make
  1465. allowances for sections in overlays. The default behaviour can be
  1466. restored by using the command-line switch @option{--check-sections}.
  1467. Section overlap is not usually checked for relocatable links. You can
  1468. force checking in that case by using the @option{--check-sections}
  1469. option.
  1470. @kindex --copy-dt-needed-entries
  1471. @kindex --no-copy-dt-needed-entries
  1472. @item --copy-dt-needed-entries
  1473. @itemx --no-copy-dt-needed-entries
  1474. This option affects the treatment of dynamic libraries referred to
  1475. by DT_NEEDED tags @emph{inside} ELF dynamic libraries mentioned on the
  1476. command line. Normally the linker won't add a DT_NEEDED tag to the
  1477. output binary for each library mentioned in a DT_NEEDED tag in an
  1478. input dynamic library. With @option{--copy-dt-needed-entries}
  1479. specified on the command line however any dynamic libraries that
  1480. follow it will have their DT_NEEDED entries added. The default
  1481. behaviour can be restored with @option{--no-copy-dt-needed-entries}.
  1482. This option also has an effect on the resolution of symbols in dynamic
  1483. libraries. With @option{--copy-dt-needed-entries} dynamic libraries
  1484. mentioned on the command line will be recursively searched, following
  1485. their DT_NEEDED tags to other libraries, in order to resolve symbols
  1486. required by the output binary. With the default setting however
  1487. the searching of dynamic libraries that follow it will stop with the
  1488. dynamic library itself. No DT_NEEDED links will be traversed to resolve
  1489. symbols.
  1490. @cindex cross reference table
  1491. @kindex --cref
  1492. @item --cref
  1493. Output a cross reference table. If a linker map file is being
  1494. generated, the cross reference table is printed to the map file.
  1495. Otherwise, it is printed on the standard output.
  1496. The format of the table is intentionally simple, so that it may be
  1497. easily processed by a script if necessary. The symbols are printed out,
  1498. sorted by name. For each symbol, a list of file names is given. If the
  1499. symbol is defined, the first file listed is the location of the
  1500. definition. If the symbol is defined as a common value then any files
  1501. where this happens appear next. Finally any files that reference the
  1502. symbol are listed.
  1503. @cindex ctf variables
  1504. @kindex --ctf-variables
  1505. @kindex --no-ctf-variables
  1506. @item --ctf-variables
  1507. @item --no-ctf-variables
  1508. The CTF debuginfo format supports a section which encodes the names and
  1509. types of variables found in the program which do not appear in any symbol
  1510. table. These variables clearly cannot be looked up by address by
  1511. conventional debuggers, so the space used for their types and names is
  1512. usually wasted: the types are usually small but the names are often not.
  1513. @option{--ctf-variables} causes the generation of such a section.
  1514. The default behaviour can be restored with @option{--no-ctf-variables}.
  1515. @cindex ctf type sharing
  1516. @kindex --ctf-share-types
  1517. @item --ctf-share-types=@var{method}
  1518. Adjust the method used to share types between translation units in CTF.
  1519. @table @samp
  1520. @item share-unconflicted
  1521. Put all types that do not have ambiguous definitions into the shared dictionary,
  1522. where debuggers can easily access them, even if they only occur in one
  1523. translation unit. This is the default.
  1524. @item share-duplicated
  1525. Put only types that occur in multiple translation units into the shared
  1526. dictionary: types with only one definition go into per-translation-unit
  1527. dictionaries. Types with ambiguous definitions in multiple translation units
  1528. always go into per-translation-unit dictionaries. This tends to make the CTF
  1529. larger, but may reduce the amount of CTF in the shared dictionary. For very
  1530. large projects this may speed up opening the CTF and save memory in the CTF
  1531. consumer at runtime.
  1532. @end table
  1533. @cindex common allocation
  1534. @kindex --no-define-common
  1535. @item --no-define-common
  1536. This option inhibits the assignment of addresses to common symbols.
  1537. The script command @code{INHIBIT_COMMON_ALLOCATION} has the same effect.
  1538. @xref{Miscellaneous Commands}.
  1539. The @samp{--no-define-common} option allows decoupling
  1540. the decision to assign addresses to Common symbols from the choice
  1541. of the output file type; otherwise a non-Relocatable output type
  1542. forces assigning addresses to Common symbols.
  1543. Using @samp{--no-define-common} allows Common symbols that are referenced
  1544. from a shared library to be assigned addresses only in the main program.
  1545. This eliminates the unused duplicate space in the shared library,
  1546. and also prevents any possible confusion over resolving to the wrong
  1547. duplicate when there are many dynamic modules with specialized search
  1548. paths for runtime symbol resolution.
  1549. @cindex group allocation in linker script
  1550. @cindex section groups
  1551. @cindex COMDAT
  1552. @kindex --force-group-allocation
  1553. @item --force-group-allocation
  1554. This option causes the linker to place section group members like
  1555. normal input sections, and to delete the section groups. This is the
  1556. default behaviour for a final link but this option can be used to
  1557. change the behaviour of a relocatable link (@samp{-r}). The script
  1558. command @code{FORCE_GROUP_ALLOCATION} has the same
  1559. effect. @xref{Miscellaneous Commands}.
  1560. @cindex symbols, from command line
  1561. @kindex --defsym=@var{symbol}=@var{exp}
  1562. @item --defsym=@var{symbol}=@var{expression}
  1563. Create a global symbol in the output file, containing the absolute
  1564. address given by @var{expression}. You may use this option as many
  1565. times as necessary to define multiple symbols in the command line. A
  1566. limited form of arithmetic is supported for the @var{expression} in this
  1567. context: you may give a hexadecimal constant or the name of an existing
  1568. symbol, or use @code{+} and @code{-} to add or subtract hexadecimal
  1569. constants or symbols. If you need more elaborate expressions, consider
  1570. using the linker command language from a script (@pxref{Assignments}).
  1571. @emph{Note:} there should be no white space between @var{symbol}, the
  1572. equals sign (``@key{=}''), and @var{expression}.
  1573. The linker processes @samp{--defsym} arguments and @samp{-T} arguments
  1574. in order, placing @samp{--defsym} before @samp{-T} will define the
  1575. symbol before the linker script from @samp{-T} is processed, while
  1576. placing @samp{--defsym} after @samp{-T} will define the symbol after
  1577. the linker script has been processed. This difference has
  1578. consequences for expressions within the linker script that use the
  1579. @samp{--defsym} symbols, which order is correct will depend on what
  1580. you are trying to achieve.
  1581. @cindex demangling, from command line
  1582. @kindex --demangle[=@var{style}]
  1583. @kindex --no-demangle
  1584. @item --demangle[=@var{style}]
  1585. @itemx --no-demangle
  1586. These options control whether to demangle symbol names in error messages
  1587. and other output. When the linker is told to demangle, it tries to
  1588. present symbol names in a readable fashion: it strips leading
  1589. underscores if they are used by the object file format, and converts C++
  1590. mangled symbol names into user readable names. Different compilers have
  1591. different mangling styles. The optional demangling style argument can be used
  1592. to choose an appropriate demangling style for your compiler. The linker will
  1593. demangle by default unless the environment variable @samp{COLLECT_NO_DEMANGLE}
  1594. is set. These options may be used to override the default.
  1595. @cindex dynamic linker, from command line
  1596. @kindex -I@var{file}
  1597. @kindex --dynamic-linker=@var{file}
  1598. @item -I@var{file}
  1599. @itemx --dynamic-linker=@var{file}
  1600. Set the name of the dynamic linker. This is only meaningful when
  1601. generating dynamically linked ELF executables. The default dynamic
  1602. linker is normally correct; don't use this unless you know what you are
  1603. doing.
  1604. @kindex --no-dynamic-linker
  1605. @item --no-dynamic-linker
  1606. When producing an executable file, omit the request for a dynamic
  1607. linker to be used at load-time. This is only meaningful for ELF
  1608. executables that contain dynamic relocations, and usually requires
  1609. entry point code that is capable of processing these relocations.
  1610. @kindex --embedded-relocs
  1611. @item --embedded-relocs
  1612. This option is similar to the @option{--emit-relocs} option except
  1613. that the relocs are stored in a target-specific section. This option
  1614. is only supported by the @samp{BFIN}, @samp{CR16} and @emph{M68K}
  1615. targets.
  1616. @kindex --disable-multiple-abs-defs
  1617. @item --disable-multiple-abs-defs
  1618. Do not allow multiple definitions with symbols included
  1619. in filename invoked by -R or --just-symbols
  1620. @kindex --fatal-warnings
  1621. @kindex --no-fatal-warnings
  1622. @item --fatal-warnings
  1623. @itemx --no-fatal-warnings
  1624. Treat all warnings as errors. The default behaviour can be restored
  1625. with the option @option{--no-fatal-warnings}.
  1626. @kindex --force-exe-suffix
  1627. @item --force-exe-suffix
  1628. Make sure that an output file has a .exe suffix.
  1629. If a successfully built fully linked output file does not have a
  1630. @code{.exe} or @code{.dll} suffix, this option forces the linker to copy
  1631. the output file to one of the same name with a @code{.exe} suffix. This
  1632. option is useful when using unmodified Unix makefiles on a Microsoft
  1633. Windows host, since some versions of Windows won't run an image unless
  1634. it ends in a @code{.exe} suffix.
  1635. @kindex --gc-sections
  1636. @kindex --no-gc-sections
  1637. @cindex garbage collection
  1638. @item --gc-sections
  1639. @itemx --no-gc-sections
  1640. Enable garbage collection of unused input sections. It is ignored on
  1641. targets that do not support this option. The default behaviour (of not
  1642. performing this garbage collection) can be restored by specifying
  1643. @samp{--no-gc-sections} on the command line. Note that garbage
  1644. collection for COFF and PE format targets is supported, but the
  1645. implementation is currently considered to be experimental.
  1646. @samp{--gc-sections} decides which input sections are used by
  1647. examining symbols and relocations. The section containing the entry
  1648. symbol and all sections containing symbols undefined on the
  1649. command-line will be kept, as will sections containing symbols
  1650. referenced by dynamic objects. Note that when building shared
  1651. libraries, the linker must assume that any visible symbol is
  1652. referenced. Once this initial set of sections has been determined,
  1653. the linker recursively marks as used any section referenced by their
  1654. relocations. See @samp{--entry}, @samp{--undefined}, and
  1655. @samp{--gc-keep-exported}.
  1656. This option can be set when doing a partial link (enabled with option
  1657. @samp{-r}). In this case the root of symbols kept must be explicitly
  1658. specified either by one of the options @samp{--entry},
  1659. @samp{--undefined}, or @samp{--gc-keep-exported} or by a @code{ENTRY}
  1660. command in the linker script.
  1661. As a GNU extension, ELF input sections marked with the
  1662. @code{SHF_GNU_RETAIN} flag will not be garbage collected.
  1663. @kindex --print-gc-sections
  1664. @kindex --no-print-gc-sections
  1665. @cindex garbage collection
  1666. @item --print-gc-sections
  1667. @itemx --no-print-gc-sections
  1668. List all sections removed by garbage collection. The listing is
  1669. printed on stderr. This option is only effective if garbage
  1670. collection has been enabled via the @samp{--gc-sections}) option. The
  1671. default behaviour (of not listing the sections that are removed) can
  1672. be restored by specifying @samp{--no-print-gc-sections} on the command
  1673. line.
  1674. @kindex --gc-keep-exported
  1675. @cindex garbage collection
  1676. @item --gc-keep-exported
  1677. When @samp{--gc-sections} is enabled, this option prevents garbage
  1678. collection of unused input sections that contain global symbols having
  1679. default or protected visibility. This option is intended to be used for
  1680. executables where unreferenced sections would otherwise be garbage
  1681. collected regardless of the external visibility of contained symbols.
  1682. Note that this option has no effect when linking shared objects since
  1683. it is already the default behaviour. This option is only supported for
  1684. ELF format targets.
  1685. @kindex --print-output-format
  1686. @cindex output format
  1687. @item --print-output-format
  1688. Print the name of the default output format (perhaps influenced by
  1689. other command-line options). This is the string that would appear
  1690. in an @code{OUTPUT_FORMAT} linker script command (@pxref{File Commands}).
  1691. @kindex --print-memory-usage
  1692. @cindex memory usage
  1693. @item --print-memory-usage
  1694. Print used size, total size and used size of memory regions created with
  1695. the @ref{MEMORY} command. This is useful on embedded targets to have a
  1696. quick view of amount of free memory. The format of the output has one
  1697. headline and one line per region. It is both human readable and easily
  1698. parsable by tools. Here is an example of an output:
  1699. @smallexample
  1700. Memory region Used Size Region Size %age Used
  1701. ROM: 256 KB 1 MB 25.00%
  1702. RAM: 32 B 2 GB 0.00%
  1703. @end smallexample
  1704. @cindex help
  1705. @cindex usage
  1706. @kindex --help
  1707. @item --help
  1708. Print a summary of the command-line options on the standard output and exit.
  1709. @kindex --target-help
  1710. @item --target-help
  1711. Print a summary of all target-specific options on the standard output and exit.
  1712. @kindex -Map=@var{mapfile}
  1713. @item -Map=@var{mapfile}
  1714. Print a link map to the file @var{mapfile}. See the description of the
  1715. @option{-M} option, above. If @var{mapfile} is just the character
  1716. @code{-} then the map will be written to stdout.
  1717. Specifying a directory as @var{mapfile} causes the linker map to be
  1718. written as a file inside the directory. Normally name of the file
  1719. inside the directory is computed as the basename of the @var{output}
  1720. file with @code{.map} appended. If however the special character
  1721. @code{%} is used then this will be replaced by the full path of the
  1722. output file. Additionally if there are any characters after the
  1723. @var{%} symbol then @code{.map} will no longer be appended.
  1724. @smallexample
  1725. -o foo.exe -Map=bar [Creates ./bar]
  1726. -o ../dir/foo.exe -Map=bar [Creates ./bar]
  1727. -o foo.exe -Map=../dir [Creates ../dir/foo.exe.map]
  1728. -o ../dir2/foo.exe -Map=../dir [Creates ../dir/foo.exe.map]
  1729. -o foo.exe -Map=% [Creates ./foo.exe.map]
  1730. -o ../dir/foo.exe -Map=% [Creates ../dir/foo.exe.map]
  1731. -o foo.exe -Map=%.bar [Creates ./foo.exe.bar]
  1732. -o ../dir/foo.exe -Map=%.bar [Creates ../dir/foo.exe.bar]
  1733. -o ../dir2/foo.exe -Map=../dir/% [Creates ../dir/../dir2/foo.exe.map]
  1734. -o ../dir2/foo.exe -Map=../dir/%.bar [Creates ../dir/../dir2/foo.exe.bar]
  1735. @end smallexample
  1736. It is an error to specify more than one @code{%} character.
  1737. If the map file already exists then it will be overwritten by this
  1738. operation.
  1739. @cindex memory usage
  1740. @kindex --no-keep-memory
  1741. @item --no-keep-memory
  1742. @command{ld} normally optimizes for speed over memory usage by caching the
  1743. symbol tables of input files in memory. This option tells @command{ld} to
  1744. instead optimize for memory usage, by rereading the symbol tables as
  1745. necessary. This may be required if @command{ld} runs out of memory space
  1746. while linking a large executable.
  1747. @kindex --no-undefined
  1748. @kindex -z defs
  1749. @kindex -z undefs
  1750. @item --no-undefined
  1751. @itemx -z defs
  1752. Report unresolved symbol references from regular object files. This
  1753. is done even if the linker is creating a non-symbolic shared library.
  1754. The switch @option{--[no-]allow-shlib-undefined} controls the
  1755. behaviour for reporting unresolved references found in shared
  1756. libraries being linked in.
  1757. The effects of this option can be reverted by using @code{-z undefs}.
  1758. @kindex --allow-multiple-definition
  1759. @kindex -z muldefs
  1760. @item --allow-multiple-definition
  1761. @itemx -z muldefs
  1762. Normally when a symbol is defined multiple times, the linker will
  1763. report a fatal error. These options allow multiple definitions and the
  1764. first definition will be used.
  1765. @kindex --allow-shlib-undefined
  1766. @kindex --no-allow-shlib-undefined
  1767. @item --allow-shlib-undefined
  1768. @itemx --no-allow-shlib-undefined
  1769. Allows or disallows undefined symbols in shared libraries.
  1770. This switch is similar to @option{--no-undefined} except that it
  1771. determines the behaviour when the undefined symbols are in a
  1772. shared library rather than a regular object file. It does not affect
  1773. how undefined symbols in regular object files are handled.
  1774. The default behaviour is to report errors for any undefined symbols
  1775. referenced in shared libraries if the linker is being used to create
  1776. an executable, but to allow them if the linker is being used to create
  1777. a shared library.
  1778. The reasons for allowing undefined symbol references in shared
  1779. libraries specified at link time are that:
  1780. @itemize @bullet
  1781. @item
  1782. A shared library specified at link time may not be the same as the one
  1783. that is available at load time, so the symbol might actually be
  1784. resolvable at load time.
  1785. @item
  1786. There are some operating systems, eg BeOS and HPPA, where undefined
  1787. symbols in shared libraries are normal.
  1788. The BeOS kernel for example patches shared libraries at load time to
  1789. select whichever function is most appropriate for the current
  1790. architecture. This is used, for example, to dynamically select an
  1791. appropriate memset function.
  1792. @end itemize
  1793. @kindex --error-handling-script=@var{scriptname}
  1794. @item --error-handling-script=@var{scriptname}
  1795. If this option is provided then the linker will invoke
  1796. @var{scriptname} whenever an error is encountered. Currently however
  1797. only two kinds of error are supported: missing symbols and missing
  1798. libraries. Two arguments will be passed to script: the keyword
  1799. ``undefined-symbol'' or `missing-lib'' and the @var{name} of the
  1800. undefined symbol or missing library. The intention is that the script
  1801. will provide suggestions to the user as to where the symbol or library
  1802. might be found. After the script has finished then the normal linker
  1803. error message will be displayed.
  1804. The availability of this option is controlled by a configure time
  1805. switch, so it may not be present in specific implementations.
  1806. @kindex --no-undefined-version
  1807. @item --no-undefined-version
  1808. Normally when a symbol has an undefined version, the linker will ignore
  1809. it. This option disallows symbols with undefined version and a fatal error
  1810. will be issued instead.
  1811. @kindex --default-symver
  1812. @item --default-symver
  1813. Create and use a default symbol version (the soname) for unversioned
  1814. exported symbols.
  1815. @kindex --default-imported-symver
  1816. @item --default-imported-symver
  1817. Create and use a default symbol version (the soname) for unversioned
  1818. imported symbols.
  1819. @kindex --no-warn-mismatch
  1820. @item --no-warn-mismatch
  1821. Normally @command{ld} will give an error if you try to link together input
  1822. files that are mismatched for some reason, perhaps because they have
  1823. been compiled for different processors or for different endiannesses.
  1824. This option tells @command{ld} that it should silently permit such possible
  1825. errors. This option should only be used with care, in cases when you
  1826. have taken some special action that ensures that the linker errors are
  1827. inappropriate.
  1828. @kindex --no-warn-search-mismatch
  1829. @item --no-warn-search-mismatch
  1830. Normally @command{ld} will give a warning if it finds an incompatible
  1831. library during a library search. This option silences the warning.
  1832. @kindex --no-whole-archive
  1833. @item --no-whole-archive
  1834. Turn off the effect of the @option{--whole-archive} option for subsequent
  1835. archive files.
  1836. @cindex output file after errors
  1837. @kindex --noinhibit-exec
  1838. @item --noinhibit-exec
  1839. Retain the executable output file whenever it is still usable.
  1840. Normally, the linker will not produce an output file if it encounters
  1841. errors during the link process; it exits without writing an output file
  1842. when it issues any error whatsoever.
  1843. @kindex -nostdlib
  1844. @item -nostdlib
  1845. Only search library directories explicitly specified on the
  1846. command line. Library directories specified in linker scripts
  1847. (including linker scripts specified on the command line) are ignored.
  1848. @ifclear SingleFormat
  1849. @kindex --oformat=@var{output-format}
  1850. @item --oformat=@var{output-format}
  1851. @command{ld} may be configured to support more than one kind of object
  1852. file. If your @command{ld} is configured this way, you can use the
  1853. @samp{--oformat} option to specify the binary format for the output
  1854. object file. Even when @command{ld} is configured to support alternative
  1855. object formats, you don't usually need to specify this, as @command{ld}
  1856. should be configured to produce as a default output format the most
  1857. usual format on each machine. @var{output-format} is a text string, the
  1858. name of a particular format supported by the BFD libraries. (You can
  1859. list the available binary formats with @samp{objdump -i}.) The script
  1860. command @code{OUTPUT_FORMAT} can also specify the output format, but
  1861. this option overrides it. @xref{BFD}.
  1862. @end ifclear
  1863. @kindex --out-implib
  1864. @item --out-implib @var{file}
  1865. Create an import library in @var{file} corresponding to the executable
  1866. the linker is generating (eg. a DLL or ELF program). This import
  1867. library (which should be called @code{*.dll.a} or @code{*.a} for DLLs)
  1868. may be used to link clients against the generated executable; this
  1869. behaviour makes it possible to skip a separate import library creation
  1870. step (eg. @code{dlltool} for DLLs). This option is only available for
  1871. the i386 PE and ELF targetted ports of the linker.
  1872. @kindex -pie
  1873. @kindex --pic-executable
  1874. @item -pie
  1875. @itemx --pic-executable
  1876. @cindex position independent executables
  1877. Create a position independent executable. This is currently only supported on
  1878. ELF platforms. Position independent executables are similar to shared
  1879. libraries in that they are relocated by the dynamic linker to the virtual
  1880. address the OS chooses for them (which can vary between invocations). Like
  1881. normal dynamically linked executables they can be executed and symbols
  1882. defined in the executable cannot be overridden by shared libraries.
  1883. @kindex -no-pie
  1884. @item -no-pie
  1885. @cindex position dependent executables
  1886. Create a position dependent executable. This is the default.
  1887. @kindex -qmagic
  1888. @item -qmagic
  1889. This option is ignored for Linux compatibility.
  1890. @kindex -Qy
  1891. @item -Qy
  1892. This option is ignored for SVR4 compatibility.
  1893. @kindex --relax
  1894. @cindex synthesizing linker
  1895. @cindex relaxing addressing modes
  1896. @cindex --no-relax
  1897. @item --relax
  1898. @itemx --no-relax
  1899. An option with machine dependent effects.
  1900. @ifset GENERIC
  1901. This option is only supported on a few targets.
  1902. @end ifset
  1903. @ifset H8300
  1904. @xref{H8/300,,@command{ld} and the H8/300}.
  1905. @end ifset
  1906. @ifset XTENSA
  1907. @xref{Xtensa,, @command{ld} and Xtensa Processors}.
  1908. @end ifset
  1909. @ifset M68HC11
  1910. @xref{M68HC11/68HC12,,@command{ld} and the 68HC11 and 68HC12}.
  1911. @end ifset
  1912. @ifset NIOSII
  1913. @xref{Nios II,,@command{ld} and the Altera Nios II}.
  1914. @end ifset
  1915. @ifset POWERPC
  1916. @xref{PowerPC ELF32,,@command{ld} and PowerPC 32-bit ELF Support}.
  1917. @end ifset
  1918. On some platforms the @option{--relax} option performs target specific,
  1919. global optimizations that become possible when the linker resolves
  1920. addressing in the program, such as relaxing address modes,
  1921. synthesizing new instructions, selecting shorter version of current
  1922. instructions, and combining constant values.
  1923. On some platforms these link time global optimizations may make symbolic
  1924. debugging of the resulting executable impossible.
  1925. @ifset GENERIC
  1926. This is known to be the case for the Matsushita MN10200 and MN10300
  1927. family of processors.
  1928. @end ifset
  1929. On platforms where the feature is supported, the option
  1930. @option{--no-relax} will disable it.
  1931. On platforms where the feature is not supported, both @option{--relax}
  1932. and @option{--no-relax} are accepted, but ignored.
  1933. @cindex retaining specified symbols
  1934. @cindex stripping all but some symbols
  1935. @cindex symbols, retaining selectively
  1936. @kindex --retain-symbols-file=@var{filename}
  1937. @item --retain-symbols-file=@var{filename}
  1938. Retain @emph{only} the symbols listed in the file @var{filename},
  1939. discarding all others. @var{filename} is simply a flat file, with one
  1940. symbol name per line. This option is especially useful in environments
  1941. @ifset GENERIC
  1942. (such as VxWorks)
  1943. @end ifset
  1944. where a large global symbol table is accumulated gradually, to conserve
  1945. run-time memory.
  1946. @samp{--retain-symbols-file} does @emph{not} discard undefined symbols,
  1947. or symbols needed for relocations.
  1948. You may only specify @samp{--retain-symbols-file} once in the command
  1949. line. It overrides @samp{-s} and @samp{-S}.
  1950. @ifset GENERIC
  1951. @item -rpath=@var{dir}
  1952. @cindex runtime library search path
  1953. @kindex -rpath=@var{dir}
  1954. Add a directory to the runtime library search path. This is used when
  1955. linking an ELF executable with shared objects. All @option{-rpath}
  1956. arguments are concatenated and passed to the runtime linker, which uses
  1957. them to locate shared objects at runtime.
  1958. The @option{-rpath} option is also used when locating shared objects which
  1959. are needed by shared objects explicitly included in the link; see the
  1960. description of the @option{-rpath-link} option. Searching @option{-rpath}
  1961. in this way is only supported by native linkers and cross linkers which
  1962. have been configured with the @option{--with-sysroot} option.
  1963. If @option{-rpath} is not used when linking an ELF executable, the
  1964. contents of the environment variable @code{LD_RUN_PATH} will be used if it
  1965. is defined.
  1966. The @option{-rpath} option may also be used on SunOS. By default, on
  1967. SunOS, the linker will form a runtime search path out of all the
  1968. @option{-L} options it is given. If a @option{-rpath} option is used, the
  1969. runtime search path will be formed exclusively using the @option{-rpath}
  1970. options, ignoring the @option{-L} options. This can be useful when using
  1971. gcc, which adds many @option{-L} options which may be on NFS mounted
  1972. file systems.
  1973. For compatibility with other ELF linkers, if the @option{-R} option is
  1974. followed by a directory name, rather than a file name, it is treated as
  1975. the @option{-rpath} option.
  1976. @end ifset
  1977. @ifset GENERIC
  1978. @cindex link-time runtime library search path
  1979. @kindex -rpath-link=@var{dir}
  1980. @item -rpath-link=@var{dir}
  1981. When using ELF or SunOS, one shared library may require another. This
  1982. happens when an @code{ld -shared} link includes a shared library as one
  1983. of the input files.
  1984. When the linker encounters such a dependency when doing a non-shared,
  1985. non-relocatable link, it will automatically try to locate the required
  1986. shared library and include it in the link, if it is not included
  1987. explicitly. In such a case, the @option{-rpath-link} option
  1988. specifies the first set of directories to search. The
  1989. @option{-rpath-link} option may specify a sequence of directory names
  1990. either by specifying a list of names separated by colons, or by
  1991. appearing multiple times.
  1992. The tokens @var{$ORIGIN} and @var{$LIB} can appear in these search
  1993. directories. They will be replaced by the full path to the directory
  1994. containing the program or shared object in the case of @var{$ORIGIN}
  1995. and either @samp{lib} - for 32-bit binaries - or @samp{lib64} - for
  1996. 64-bit binaries - in the case of @var{$LIB}.
  1997. The alternative form of these tokens - @var{$@{ORIGIN@}} and
  1998. @var{$@{LIB@}} can also be used. The token @var{$PLATFORM} is not
  1999. supported.
  2000. This option should be used with caution as it overrides the search path
  2001. that may have been hard compiled into a shared library. In such a case it
  2002. is possible to use unintentionally a different search path than the
  2003. runtime linker would do.
  2004. The linker uses the following search paths to locate required shared
  2005. libraries:
  2006. @enumerate
  2007. @item
  2008. Any directories specified by @option{-rpath-link} options.
  2009. @item
  2010. Any directories specified by @option{-rpath} options. The difference
  2011. between @option{-rpath} and @option{-rpath-link} is that directories
  2012. specified by @option{-rpath} options are included in the executable and
  2013. used at runtime, whereas the @option{-rpath-link} option is only effective
  2014. at link time. Searching @option{-rpath} in this way is only supported
  2015. by native linkers and cross linkers which have been configured with
  2016. the @option{--with-sysroot} option.
  2017. @item
  2018. On an ELF system, for native linkers, if the @option{-rpath} and
  2019. @option{-rpath-link} options were not used, search the contents of the
  2020. environment variable @code{LD_RUN_PATH}.
  2021. @item
  2022. On SunOS, if the @option{-rpath} option was not used, search any
  2023. directories specified using @option{-L} options.
  2024. @item
  2025. For a native linker, search the contents of the environment
  2026. variable @code{LD_LIBRARY_PATH}.
  2027. @item
  2028. For a native ELF linker, the directories in @code{DT_RUNPATH} or
  2029. @code{DT_RPATH} of a shared library are searched for shared
  2030. libraries needed by it. The @code{DT_RPATH} entries are ignored if
  2031. @code{DT_RUNPATH} entries exist.
  2032. @item
  2033. For a linker for a Linux system, if the file @file{/etc/ld.so.conf}
  2034. exists, the list of directories found in that file. Note: the path
  2035. to this file is prefixed with the @code{sysroot} value, if that is
  2036. defined, and then any @code{prefix} string if the linker was
  2037. configured with the @command{--prefix=<path>} option.
  2038. @item
  2039. For a native linker on a FreeBSD system, any directories specified by
  2040. the @code{_PATH_ELF_HINTS} macro defined in the @file{elf-hints.h}
  2041. header file.
  2042. @item
  2043. Any directories specified by a @code{SEARCH_DIR} command in a
  2044. linker script given on the command line, including scripts specified
  2045. by @option{-T} (but not @option{-dT}).
  2046. @item
  2047. The default directories, normally @file{/lib} and @file{/usr/lib}.
  2048. @item
  2049. Any directories specified by a plugin LDPT_SET_EXTRA_LIBRARY_PATH.
  2050. @item
  2051. Any directories specified by a @code{SEARCH_DIR} command in a default
  2052. linker script.
  2053. @end enumerate
  2054. Note however on Linux based systems there is an additional caveat: If
  2055. the @option{--as-needed} option is active @emph{and} a shared library
  2056. is located which would normally satisfy the search @emph{and} this
  2057. library does not have DT_NEEDED tag for @file{libc.so}
  2058. @emph{and} there is a shared library later on in the set of search
  2059. directories which also satisfies the search @emph{and}
  2060. this second shared library does have a DT_NEEDED tag for
  2061. @file{libc.so} @emph{then} the second library will be selected instead
  2062. of the first.
  2063. If the required shared library is not found, the linker will issue a
  2064. warning and continue with the link.
  2065. @end ifset
  2066. @kindex -shared
  2067. @kindex -Bshareable
  2068. @item -shared
  2069. @itemx -Bshareable
  2070. @cindex shared libraries
  2071. Create a shared library. This is currently only supported on ELF, XCOFF
  2072. and SunOS platforms. On SunOS, the linker will automatically create a
  2073. shared library if the @option{-e} option is not used and there are
  2074. undefined symbols in the link.
  2075. @kindex --sort-common
  2076. @item --sort-common
  2077. @itemx --sort-common=ascending
  2078. @itemx --sort-common=descending
  2079. This option tells @command{ld} to sort the common symbols by alignment in
  2080. ascending or descending order when it places them in the appropriate output
  2081. sections. The symbol alignments considered are sixteen-byte or larger,
  2082. eight-byte, four-byte, two-byte, and one-byte. This is to prevent gaps
  2083. between symbols due to alignment constraints. If no sorting order is
  2084. specified, then descending order is assumed.
  2085. @kindex --sort-section=name
  2086. @item --sort-section=name
  2087. This option will apply @code{SORT_BY_NAME} to all wildcard section
  2088. patterns in the linker script.
  2089. @kindex --sort-section=alignment
  2090. @item --sort-section=alignment
  2091. This option will apply @code{SORT_BY_ALIGNMENT} to all wildcard section
  2092. patterns in the linker script.
  2093. @kindex --spare-dynamic-tags
  2094. @item --spare-dynamic-tags=@var{count}
  2095. This option specifies the number of empty slots to leave in the
  2096. .dynamic section of ELF shared objects. Empty slots may be needed by
  2097. post processing tools, such as the prelinker. The default is 5.
  2098. @kindex --split-by-file
  2099. @item --split-by-file[=@var{size}]
  2100. Similar to @option{--split-by-reloc} but creates a new output section for
  2101. each input file when @var{size} is reached. @var{size} defaults to a
  2102. size of 1 if not given.
  2103. @kindex --split-by-reloc
  2104. @item --split-by-reloc[=@var{count}]
  2105. Tries to creates extra sections in the output file so that no single
  2106. output section in the file contains more than @var{count} relocations.
  2107. This is useful when generating huge relocatable files for downloading into
  2108. certain real time kernels with the COFF object file format; since COFF
  2109. cannot represent more than 65535 relocations in a single section. Note
  2110. that this will fail to work with object file formats which do not
  2111. support arbitrary sections. The linker will not split up individual
  2112. input sections for redistribution, so if a single input section contains
  2113. more than @var{count} relocations one output section will contain that
  2114. many relocations. @var{count} defaults to a value of 32768.
  2115. @kindex --stats
  2116. @item --stats
  2117. Compute and display statistics about the operation of the linker, such
  2118. as execution time and memory usage.
  2119. @kindex --sysroot=@var{directory}
  2120. @item --sysroot=@var{directory}
  2121. Use @var{directory} as the location of the sysroot, overriding the
  2122. configure-time default. This option is only supported by linkers
  2123. that were configured using @option{--with-sysroot}.
  2124. @kindex --task-link
  2125. @item --task-link
  2126. This is used by COFF/PE based targets to create a task-linked object
  2127. file where all of the global symbols have been converted to statics.
  2128. @kindex --traditional-format
  2129. @cindex traditional format
  2130. @item --traditional-format
  2131. For some targets, the output of @command{ld} is different in some ways from
  2132. the output of some existing linker. This switch requests @command{ld} to
  2133. use the traditional format instead.
  2134. @cindex dbx
  2135. For example, on SunOS, @command{ld} combines duplicate entries in the
  2136. symbol string table. This can reduce the size of an output file with
  2137. full debugging information by over 30 percent. Unfortunately, the SunOS
  2138. @code{dbx} program can not read the resulting program (@code{gdb} has no
  2139. trouble). The @samp{--traditional-format} switch tells @command{ld} to not
  2140. combine duplicate entries.
  2141. @kindex --section-start=@var{sectionname}=@var{org}
  2142. @item --section-start=@var{sectionname}=@var{org}
  2143. Locate a section in the output file at the absolute
  2144. address given by @var{org}. You may use this option as many
  2145. times as necessary to locate multiple sections in the command
  2146. line.
  2147. @var{org} must be a single hexadecimal integer;
  2148. for compatibility with other linkers, you may omit the leading
  2149. @samp{0x} usually associated with hexadecimal values. @emph{Note:} there
  2150. should be no white space between @var{sectionname}, the equals
  2151. sign (``@key{=}''), and @var{org}.
  2152. @kindex -Tbss=@var{org}
  2153. @kindex -Tdata=@var{org}
  2154. @kindex -Ttext=@var{org}
  2155. @cindex segment origins, cmd line
  2156. @item -Tbss=@var{org}
  2157. @itemx -Tdata=@var{org}
  2158. @itemx -Ttext=@var{org}
  2159. Same as @option{--section-start}, with @code{.bss}, @code{.data} or
  2160. @code{.text} as the @var{sectionname}.
  2161. @kindex -Ttext-segment=@var{org}
  2162. @item -Ttext-segment=@var{org}
  2163. @cindex text segment origin, cmd line
  2164. When creating an ELF executable, it will set the address of the first
  2165. byte of the text segment.
  2166. @kindex -Trodata-segment=@var{org}
  2167. @item -Trodata-segment=@var{org}
  2168. @cindex rodata segment origin, cmd line
  2169. When creating an ELF executable or shared object for a target where
  2170. the read-only data is in its own segment separate from the executable
  2171. text, it will set the address of the first byte of the read-only data segment.
  2172. @kindex -Tldata-segment=@var{org}
  2173. @item -Tldata-segment=@var{org}
  2174. @cindex ldata segment origin, cmd line
  2175. When creating an ELF executable or shared object for x86-64 medium memory
  2176. model, it will set the address of the first byte of the ldata segment.
  2177. @kindex --unresolved-symbols
  2178. @item --unresolved-symbols=@var{method}
  2179. Determine how to handle unresolved symbols. There are four possible
  2180. values for @samp{method}:
  2181. @table @samp
  2182. @item ignore-all
  2183. Do not report any unresolved symbols.
  2184. @item report-all
  2185. Report all unresolved symbols. This is the default.
  2186. @item ignore-in-object-files
  2187. Report unresolved symbols that are contained in shared libraries, but
  2188. ignore them if they come from regular object files.
  2189. @item ignore-in-shared-libs
  2190. Report unresolved symbols that come from regular object files, but
  2191. ignore them if they come from shared libraries. This can be useful
  2192. when creating a dynamic binary and it is known that all the shared
  2193. libraries that it should be referencing are included on the linker's
  2194. command line.
  2195. @end table
  2196. The behaviour for shared libraries on their own can also be controlled
  2197. by the @option{--[no-]allow-shlib-undefined} option.
  2198. Normally the linker will generate an error message for each reported
  2199. unresolved symbol but the option @option{--warn-unresolved-symbols}
  2200. can change this to a warning.
  2201. @kindex --verbose[=@var{NUMBER}]
  2202. @cindex verbose[=@var{NUMBER}]
  2203. @item --dll-verbose
  2204. @itemx --verbose[=@var{NUMBER}]
  2205. Display the version number for @command{ld} and list the linker emulations
  2206. supported. Display which input files can and cannot be opened. Display
  2207. the linker script being used by the linker. If the optional @var{NUMBER}
  2208. argument > 1, plugin symbol status will also be displayed.
  2209. @kindex --version-script=@var{version-scriptfile}
  2210. @cindex version script, symbol versions
  2211. @item --version-script=@var{version-scriptfile}
  2212. Specify the name of a version script to the linker. This is typically
  2213. used when creating shared libraries to specify additional information
  2214. about the version hierarchy for the library being created. This option
  2215. is only fully supported on ELF platforms which support shared libraries;
  2216. see @ref{VERSION}. It is partially supported on PE platforms, which can
  2217. use version scripts to filter symbol visibility in auto-export mode: any
  2218. symbols marked @samp{local} in the version script will not be exported.
  2219. @xref{WIN32}.
  2220. @kindex --warn-common
  2221. @cindex warnings, on combining symbols
  2222. @cindex combining symbols, warnings on
  2223. @item --warn-common
  2224. Warn when a common symbol is combined with another common symbol or with
  2225. a symbol definition. Unix linkers allow this somewhat sloppy practice,
  2226. but linkers on some other operating systems do not. This option allows
  2227. you to find potential problems from combining global symbols.
  2228. Unfortunately, some C libraries use this practice, so you may get some
  2229. warnings about symbols in the libraries as well as in your programs.
  2230. There are three kinds of global symbols, illustrated here by C examples:
  2231. @table @samp
  2232. @item int i = 1;
  2233. A definition, which goes in the initialized data section of the output
  2234. file.
  2235. @item extern int i;
  2236. An undefined reference, which does not allocate space.
  2237. There must be either a definition or a common symbol for the
  2238. variable somewhere.
  2239. @item int i;
  2240. A common symbol. If there are only (one or more) common symbols for a
  2241. variable, it goes in the uninitialized data area of the output file.
  2242. The linker merges multiple common symbols for the same variable into a
  2243. single symbol. If they are of different sizes, it picks the largest
  2244. size. The linker turns a common symbol into a declaration, if there is
  2245. a definition of the same variable.
  2246. @end table
  2247. The @samp{--warn-common} option can produce five kinds of warnings.
  2248. Each warning consists of a pair of lines: the first describes the symbol
  2249. just encountered, and the second describes the previous symbol
  2250. encountered with the same name. One or both of the two symbols will be
  2251. a common symbol.
  2252. @enumerate
  2253. @item
  2254. Turning a common symbol into a reference, because there is already a
  2255. definition for the symbol.
  2256. @smallexample
  2257. @var{file}(@var{section}): warning: common of `@var{symbol}'
  2258. overridden by definition
  2259. @var{file}(@var{section}): warning: defined here
  2260. @end smallexample
  2261. @item
  2262. Turning a common symbol into a reference, because a later definition for
  2263. the symbol is encountered. This is the same as the previous case,
  2264. except that the symbols are encountered in a different order.
  2265. @smallexample
  2266. @var{file}(@var{section}): warning: definition of `@var{symbol}'
  2267. overriding common
  2268. @var{file}(@var{section}): warning: common is here
  2269. @end smallexample
  2270. @item
  2271. Merging a common symbol with a previous same-sized common symbol.
  2272. @smallexample
  2273. @var{file}(@var{section}): warning: multiple common
  2274. of `@var{symbol}'
  2275. @var{file}(@var{section}): warning: previous common is here
  2276. @end smallexample
  2277. @item
  2278. Merging a common symbol with a previous larger common symbol.
  2279. @smallexample
  2280. @var{file}(@var{section}): warning: common of `@var{symbol}'
  2281. overridden by larger common
  2282. @var{file}(@var{section}): warning: larger common is here
  2283. @end smallexample
  2284. @item
  2285. Merging a common symbol with a previous smaller common symbol. This is
  2286. the same as the previous case, except that the symbols are
  2287. encountered in a different order.
  2288. @smallexample
  2289. @var{file}(@var{section}): warning: common of `@var{symbol}'
  2290. overriding smaller common
  2291. @var{file}(@var{section}): warning: smaller common is here
  2292. @end smallexample
  2293. @end enumerate
  2294. @kindex --warn-constructors
  2295. @item --warn-constructors
  2296. Warn if any global constructors are used. This is only useful for a few
  2297. object file formats. For formats like COFF or ELF, the linker can not
  2298. detect the use of global constructors.
  2299. @kindex --warn-multiple-gp
  2300. @item --warn-multiple-gp
  2301. Warn if multiple global pointer values are required in the output file.
  2302. This is only meaningful for certain processors, such as the Alpha.
  2303. Specifically, some processors put large-valued constants in a special
  2304. section. A special register (the global pointer) points into the middle
  2305. of this section, so that constants can be loaded efficiently via a
  2306. base-register relative addressing mode. Since the offset in
  2307. base-register relative mode is fixed and relatively small (e.g., 16
  2308. bits), this limits the maximum size of the constant pool. Thus, in
  2309. large programs, it is often necessary to use multiple global pointer
  2310. values in order to be able to address all possible constants. This
  2311. option causes a warning to be issued whenever this case occurs.
  2312. @kindex --warn-once
  2313. @cindex warnings, on undefined symbols
  2314. @cindex undefined symbols, warnings on
  2315. @item --warn-once
  2316. Only warn once for each undefined symbol, rather than once per module
  2317. which refers to it.
  2318. @kindex --warn-section-align
  2319. @cindex warnings, on section alignment
  2320. @cindex section alignment, warnings on
  2321. @item --warn-section-align
  2322. Warn if the address of an output section is changed because of
  2323. alignment. Typically, the alignment will be set by an input section.
  2324. The address will only be changed if it not explicitly specified; that
  2325. is, if the @code{SECTIONS} command does not specify a start address for
  2326. the section (@pxref{SECTIONS}).
  2327. @kindex --warn-textrel
  2328. @item --warn-textrel
  2329. Warn if the linker adds DT_TEXTREL to a position-independent executable
  2330. or shared object.
  2331. @kindex --warn-alternate-em
  2332. @item --warn-alternate-em
  2333. Warn if an object has alternate ELF machine code.
  2334. @kindex --warn-unresolved-symbols
  2335. @item --warn-unresolved-symbols
  2336. If the linker is going to report an unresolved symbol (see the option
  2337. @option{--unresolved-symbols}) it will normally generate an error.
  2338. This option makes it generate a warning instead.
  2339. @kindex --error-unresolved-symbols
  2340. @item --error-unresolved-symbols
  2341. This restores the linker's default behaviour of generating errors when
  2342. it is reporting unresolved symbols.
  2343. @kindex --whole-archive
  2344. @cindex including an entire archive
  2345. @item --whole-archive
  2346. For each archive mentioned on the command line after the
  2347. @option{--whole-archive} option, include every object file in the archive
  2348. in the link, rather than searching the archive for the required object
  2349. files. This is normally used to turn an archive file into a shared
  2350. library, forcing every object to be included in the resulting shared
  2351. library. This option may be used more than once.
  2352. Two notes when using this option from gcc: First, gcc doesn't know
  2353. about this option, so you have to use @option{-Wl,-whole-archive}.
  2354. Second, don't forget to use @option{-Wl,-no-whole-archive} after your
  2355. list of archives, because gcc will add its own list of archives to
  2356. your link and you may not want this flag to affect those as well.
  2357. @kindex --wrap=@var{symbol}
  2358. @item --wrap=@var{symbol}
  2359. Use a wrapper function for @var{symbol}. Any undefined reference to
  2360. @var{symbol} will be resolved to @code{__wrap_@var{symbol}}. Any
  2361. undefined reference to @code{__real_@var{symbol}} will be resolved to
  2362. @var{symbol}.
  2363. This can be used to provide a wrapper for a system function. The
  2364. wrapper function should be called @code{__wrap_@var{symbol}}. If it
  2365. wishes to call the system function, it should call
  2366. @code{__real_@var{symbol}}.
  2367. Here is a trivial example:
  2368. @smallexample
  2369. void *
  2370. __wrap_malloc (size_t c)
  2371. @{
  2372. printf ("malloc called with %zu\n", c);
  2373. return __real_malloc (c);
  2374. @}
  2375. @end smallexample
  2376. If you link other code with this file using @option{--wrap malloc}, then
  2377. all calls to @code{malloc} will call the function @code{__wrap_malloc}
  2378. instead. The call to @code{__real_malloc} in @code{__wrap_malloc} will
  2379. call the real @code{malloc} function.
  2380. You may wish to provide a @code{__real_malloc} function as well, so that
  2381. links without the @option{--wrap} option will succeed. If you do this,
  2382. you should not put the definition of @code{__real_malloc} in the same
  2383. file as @code{__wrap_malloc}; if you do, the assembler may resolve the
  2384. call before the linker has a chance to wrap it to @code{malloc}.
  2385. Only undefined references are replaced by the linker. So, translation unit
  2386. internal references to @var{symbol} are not resolved to
  2387. @code{__wrap_@var{symbol}}. In the next example, the call to @code{f} in
  2388. @code{g} is not resolved to @code{__wrap_f}.
  2389. @smallexample
  2390. int
  2391. f (void)
  2392. @{
  2393. return 123;
  2394. @}
  2395. int
  2396. g (void)
  2397. @{
  2398. return f();
  2399. @}
  2400. @end smallexample
  2401. @kindex --eh-frame-hdr
  2402. @kindex --no-eh-frame-hdr
  2403. @item --eh-frame-hdr
  2404. @itemx --no-eh-frame-hdr
  2405. Request (@option{--eh-frame-hdr}) or suppress
  2406. (@option{--no-eh-frame-hdr}) the creation of @code{.eh_frame_hdr}
  2407. section and ELF @code{PT_GNU_EH_FRAME} segment header.
  2408. @kindex --ld-generated-unwind-info
  2409. @item --no-ld-generated-unwind-info
  2410. Request creation of @code{.eh_frame} unwind info for linker
  2411. generated code sections like PLT. This option is on by default
  2412. if linker generated unwind info is supported.
  2413. @kindex --enable-new-dtags
  2414. @kindex --disable-new-dtags
  2415. @item --enable-new-dtags
  2416. @itemx --disable-new-dtags
  2417. This linker can create the new dynamic tags in ELF. But the older ELF
  2418. systems may not understand them. If you specify
  2419. @option{--enable-new-dtags}, the new dynamic tags will be created as needed
  2420. and older dynamic tags will be omitted.
  2421. If you specify @option{--disable-new-dtags}, no new dynamic tags will be
  2422. created. By default, the new dynamic tags are not created. Note that
  2423. those options are only available for ELF systems.
  2424. @kindex --hash-size=@var{number}
  2425. @item --hash-size=@var{number}
  2426. Set the default size of the linker's hash tables to a prime number
  2427. close to @var{number}. Increasing this value can reduce the length of
  2428. time it takes the linker to perform its tasks, at the expense of
  2429. increasing the linker's memory requirements. Similarly reducing this
  2430. value can reduce the memory requirements at the expense of speed.
  2431. @kindex --hash-style=@var{style}
  2432. @item --hash-style=@var{style}
  2433. Set the type of linker's hash table(s). @var{style} can be either
  2434. @code{sysv} for classic ELF @code{.hash} section, @code{gnu} for
  2435. new style GNU @code{.gnu.hash} section or @code{both} for both
  2436. the classic ELF @code{.hash} and new style GNU @code{.gnu.hash}
  2437. hash tables. The default depends upon how the linker was configured,
  2438. but for most Linux based systems it will be @code{both}.
  2439. @kindex --compress-debug-sections=none
  2440. @kindex --compress-debug-sections=zlib
  2441. @kindex --compress-debug-sections=zlib-gnu
  2442. @kindex --compress-debug-sections=zlib-gabi
  2443. @item --compress-debug-sections=none
  2444. @itemx --compress-debug-sections=zlib
  2445. @itemx --compress-debug-sections=zlib-gnu
  2446. @itemx --compress-debug-sections=zlib-gabi
  2447. On ELF platforms, these options control how DWARF debug sections are
  2448. compressed using zlib.
  2449. @option{--compress-debug-sections=none} doesn't compress DWARF debug
  2450. sections. @option{--compress-debug-sections=zlib-gnu} compresses
  2451. DWARF debug sections and renames them to begin with @samp{.zdebug}
  2452. instead of @samp{.debug}. @option{--compress-debug-sections=zlib-gabi}
  2453. also compresses DWARF debug sections, but rather than renaming them it
  2454. sets the SHF_COMPRESSED flag in the sections' headers.
  2455. The @option{--compress-debug-sections=zlib} option is an alias for
  2456. @option{--compress-debug-sections=zlib-gabi}.
  2457. Note that this option overrides any compression in input debug
  2458. sections, so if a binary is linked with @option{--compress-debug-sections=none}
  2459. for example, then any compressed debug sections in input files will be
  2460. uncompressed before they are copied into the output binary.
  2461. The default compression behaviour varies depending upon the target
  2462. involved and the configure options used to build the toolchain. The
  2463. default can be determined by examining the output from the linker's
  2464. @option{--help} option.
  2465. @kindex --reduce-memory-overheads
  2466. @item --reduce-memory-overheads
  2467. This option reduces memory requirements at ld runtime, at the expense of
  2468. linking speed. This was introduced to select the old O(n^2) algorithm
  2469. for link map file generation, rather than the new O(n) algorithm which uses
  2470. about 40% more memory for symbol storage.
  2471. Another effect of the switch is to set the default hash table size to
  2472. 1021, which again saves memory at the cost of lengthening the linker's
  2473. run time. This is not done however if the @option{--hash-size} switch
  2474. has been used.
  2475. The @option{--reduce-memory-overheads} switch may be also be used to
  2476. enable other tradeoffs in future versions of the linker.
  2477. @kindex --max-cache-size=@var{size}
  2478. @item --max-cache-size=@var{size}
  2479. @command{ld} normally caches the relocation information and symbol tables
  2480. of input files in memory with the unlimited size. This option sets the
  2481. maximum cache size to @var{size}.
  2482. @kindex --build-id
  2483. @kindex --build-id=@var{style}
  2484. @item --build-id
  2485. @itemx --build-id=@var{style}
  2486. Request the creation of a @code{.note.gnu.build-id} ELF note section
  2487. or a @code{.buildid} COFF section. The contents of the note are
  2488. unique bits identifying this linked file. @var{style} can be
  2489. @code{uuid} to use 128 random bits, @code{sha1} to use a 160-bit
  2490. @sc{SHA1} hash on the normative parts of the output contents,
  2491. @code{md5} to use a 128-bit @sc{MD5} hash on the normative parts of
  2492. the output contents, or @code{0x@var{hexstring}} to use a chosen bit
  2493. string specified as an even number of hexadecimal digits (@code{-} and
  2494. @code{:} characters between digit pairs are ignored). If @var{style}
  2495. is omitted, @code{sha1} is used.
  2496. The @code{md5} and @code{sha1} styles produces an identifier
  2497. that is always the same in an identical output file, but will be
  2498. unique among all nonidentical output files. It is not intended
  2499. to be compared as a checksum for the file's contents. A linked
  2500. file may be changed later by other tools, but the build ID bit
  2501. string identifying the original linked file does not change.
  2502. Passing @code{none} for @var{style} disables the setting from any
  2503. @code{--build-id} options earlier on the command line.
  2504. @end table
  2505. @c man end
  2506. @subsection Options Specific to i386 PE Targets
  2507. @c man begin OPTIONS
  2508. The i386 PE linker supports the @option{-shared} option, which causes
  2509. the output to be a dynamically linked library (DLL) instead of a
  2510. normal executable. You should name the output @code{*.dll} when you
  2511. use this option. In addition, the linker fully supports the standard
  2512. @code{*.def} files, which may be specified on the linker command line
  2513. like an object file (in fact, it should precede archives it exports
  2514. symbols from, to ensure that they get linked in, just like a normal
  2515. object file).
  2516. In addition to the options common to all targets, the i386 PE linker
  2517. support additional command-line options that are specific to the i386
  2518. PE target. Options that take values may be separated from their
  2519. values by either a space or an equals sign.
  2520. @table @gcctabopt
  2521. @kindex --add-stdcall-alias
  2522. @item --add-stdcall-alias
  2523. If given, symbols with a stdcall suffix (@@@var{nn}) will be exported
  2524. as-is and also with the suffix stripped.
  2525. [This option is specific to the i386 PE targeted port of the linker]
  2526. @kindex --base-file
  2527. @item --base-file @var{file}
  2528. Use @var{file} as the name of a file in which to save the base
  2529. addresses of all the relocations needed for generating DLLs with
  2530. @file{dlltool}.
  2531. [This is an i386 PE specific option]
  2532. @kindex --dll
  2533. @item --dll
  2534. Create a DLL instead of a regular executable. You may also use
  2535. @option{-shared} or specify a @code{LIBRARY} in a given @code{.def}
  2536. file.
  2537. [This option is specific to the i386 PE targeted port of the linker]
  2538. @kindex --enable-long-section-names
  2539. @kindex --disable-long-section-names
  2540. @item --enable-long-section-names
  2541. @itemx --disable-long-section-names
  2542. The PE variants of the COFF object format add an extension that permits
  2543. the use of section names longer than eight characters, the normal limit
  2544. for COFF. By default, these names are only allowed in object files, as
  2545. fully-linked executable images do not carry the COFF string table required
  2546. to support the longer names. As a GNU extension, it is possible to
  2547. allow their use in executable images as well, or to (probably pointlessly!)
  2548. disallow it in object files, by using these two options. Executable images
  2549. generated with these long section names are slightly non-standard, carrying
  2550. as they do a string table, and may generate confusing output when examined
  2551. with non-GNU PE-aware tools, such as file viewers and dumpers. However,
  2552. GDB relies on the use of PE long section names to find Dwarf-2 debug
  2553. information sections in an executable image at runtime, and so if neither
  2554. option is specified on the command-line, @command{ld} will enable long
  2555. section names, overriding the default and technically correct behaviour,
  2556. when it finds the presence of debug information while linking an executable
  2557. image and not stripping symbols.
  2558. [This option is valid for all PE targeted ports of the linker]
  2559. @kindex --enable-stdcall-fixup
  2560. @kindex --disable-stdcall-fixup
  2561. @item --enable-stdcall-fixup
  2562. @itemx --disable-stdcall-fixup
  2563. If the link finds a symbol that it cannot resolve, it will attempt to
  2564. do ``fuzzy linking'' by looking for another defined symbol that differs
  2565. only in the format of the symbol name (cdecl vs stdcall) and will
  2566. resolve that symbol by linking to the match. For example, the
  2567. undefined symbol @code{_foo} might be linked to the function
  2568. @code{_foo@@12}, or the undefined symbol @code{_bar@@16} might be linked
  2569. to the function @code{_bar}. When the linker does this, it prints a
  2570. warning, since it normally should have failed to link, but sometimes
  2571. import libraries generated from third-party dlls may need this feature
  2572. to be usable. If you specify @option{--enable-stdcall-fixup}, this
  2573. feature is fully enabled and warnings are not printed. If you specify
  2574. @option{--disable-stdcall-fixup}, this feature is disabled and such
  2575. mismatches are considered to be errors.
  2576. [This option is specific to the i386 PE targeted port of the linker]
  2577. @kindex --leading-underscore
  2578. @kindex --no-leading-underscore
  2579. @item --leading-underscore
  2580. @itemx --no-leading-underscore
  2581. For most targets default symbol-prefix is an underscore and is defined
  2582. in target's description. By this option it is possible to
  2583. disable/enable the default underscore symbol-prefix.
  2584. @cindex DLLs, creating
  2585. @kindex --export-all-symbols
  2586. @item --export-all-symbols
  2587. If given, all global symbols in the objects used to build a DLL will
  2588. be exported by the DLL. Note that this is the default if there
  2589. otherwise wouldn't be any exported symbols. When symbols are
  2590. explicitly exported via DEF files or implicitly exported via function
  2591. attributes, the default is to not export anything else unless this
  2592. option is given. Note that the symbols @code{DllMain@@12},
  2593. @code{DllEntryPoint@@0}, @code{DllMainCRTStartup@@12}, and
  2594. @code{impure_ptr} will not be automatically
  2595. exported. Also, symbols imported from other DLLs will not be
  2596. re-exported, nor will symbols specifying the DLL's internal layout
  2597. such as those beginning with @code{_head_} or ending with
  2598. @code{_iname}. In addition, no symbols from @code{libgcc},
  2599. @code{libstd++}, @code{libmingw32}, or @code{crtX.o} will be exported.
  2600. Symbols whose names begin with @code{__rtti_} or @code{__builtin_} will
  2601. not be exported, to help with C++ DLLs. Finally, there is an
  2602. extensive list of cygwin-private symbols that are not exported
  2603. (obviously, this applies on when building DLLs for cygwin targets).
  2604. These cygwin-excludes are: @code{_cygwin_dll_entry@@12},
  2605. @code{_cygwin_crt0_common@@8}, @code{_cygwin_noncygwin_dll_entry@@12},
  2606. @code{_fmode}, @code{_impure_ptr}, @code{cygwin_attach_dll},
  2607. @code{cygwin_premain0}, @code{cygwin_premain1}, @code{cygwin_premain2},
  2608. @code{cygwin_premain3}, and @code{environ}.
  2609. [This option is specific to the i386 PE targeted port of the linker]
  2610. @kindex --exclude-symbols
  2611. @item --exclude-symbols @var{symbol},@var{symbol},...
  2612. Specifies a list of symbols which should not be automatically
  2613. exported. The symbol names may be delimited by commas or colons.
  2614. [This option is specific to the i386 PE targeted port of the linker]
  2615. @kindex --exclude-all-symbols
  2616. @item --exclude-all-symbols
  2617. Specifies no symbols should be automatically exported.
  2618. [This option is specific to the i386 PE targeted port of the linker]
  2619. @kindex --file-alignment
  2620. @item --file-alignment
  2621. Specify the file alignment. Sections in the file will always begin at
  2622. file offsets which are multiples of this number. This defaults to
  2623. 512.
  2624. [This option is specific to the i386 PE targeted port of the linker]
  2625. @cindex heap size
  2626. @kindex --heap
  2627. @item --heap @var{reserve}
  2628. @itemx --heap @var{reserve},@var{commit}
  2629. Specify the number of bytes of memory to reserve (and optionally commit)
  2630. to be used as heap for this program. The default is 1MB reserved, 4K
  2631. committed.
  2632. [This option is specific to the i386 PE targeted port of the linker]
  2633. @cindex image base
  2634. @kindex --image-base
  2635. @item --image-base @var{value}
  2636. Use @var{value} as the base address of your program or dll. This is
  2637. the lowest memory location that will be used when your program or dll
  2638. is loaded. To reduce the need to relocate and improve performance of
  2639. your dlls, each should have a unique base address and not overlap any
  2640. other dlls. The default is 0x400000 for executables, and 0x10000000
  2641. for dlls.
  2642. [This option is specific to the i386 PE targeted port of the linker]
  2643. @kindex --kill-at
  2644. @item --kill-at
  2645. If given, the stdcall suffixes (@@@var{nn}) will be stripped from
  2646. symbols before they are exported.
  2647. [This option is specific to the i386 PE targeted port of the linker]
  2648. @kindex --large-address-aware
  2649. @item --large-address-aware
  2650. If given, the appropriate bit in the ``Characteristics'' field of the COFF
  2651. header is set to indicate that this executable supports virtual addresses
  2652. greater than 2 gigabytes. This should be used in conjunction with the /3GB
  2653. or /USERVA=@var{value} megabytes switch in the ``[operating systems]''
  2654. section of the BOOT.INI. Otherwise, this bit has no effect.
  2655. [This option is specific to PE targeted ports of the linker]
  2656. @kindex --disable-large-address-aware
  2657. @item --disable-large-address-aware
  2658. Reverts the effect of a previous @samp{--large-address-aware} option.
  2659. This is useful if @samp{--large-address-aware} is always set by the compiler
  2660. driver (e.g. Cygwin gcc) and the executable does not support virtual
  2661. addresses greater than 2 gigabytes.
  2662. [This option is specific to PE targeted ports of the linker]
  2663. @kindex --major-image-version
  2664. @item --major-image-version @var{value}
  2665. Sets the major number of the ``image version''. Defaults to 1.
  2666. [This option is specific to the i386 PE targeted port of the linker]
  2667. @kindex --major-os-version
  2668. @item --major-os-version @var{value}
  2669. Sets the major number of the ``os version''. Defaults to 4.
  2670. [This option is specific to the i386 PE targeted port of the linker]
  2671. @kindex --major-subsystem-version
  2672. @item --major-subsystem-version @var{value}
  2673. Sets the major number of the ``subsystem version''. Defaults to 4.
  2674. [This option is specific to the i386 PE targeted port of the linker]
  2675. @kindex --minor-image-version
  2676. @item --minor-image-version @var{value}
  2677. Sets the minor number of the ``image version''. Defaults to 0.
  2678. [This option is specific to the i386 PE targeted port of the linker]
  2679. @kindex --minor-os-version
  2680. @item --minor-os-version @var{value}
  2681. Sets the minor number of the ``os version''. Defaults to 0.
  2682. [This option is specific to the i386 PE targeted port of the linker]
  2683. @kindex --minor-subsystem-version
  2684. @item --minor-subsystem-version @var{value}
  2685. Sets the minor number of the ``subsystem version''. Defaults to 0.
  2686. [This option is specific to the i386 PE targeted port of the linker]
  2687. @cindex DEF files, creating
  2688. @cindex DLLs, creating
  2689. @kindex --output-def
  2690. @item --output-def @var{file}
  2691. The linker will create the file @var{file} which will contain a DEF
  2692. file corresponding to the DLL the linker is generating. This DEF file
  2693. (which should be called @code{*.def}) may be used to create an import
  2694. library with @code{dlltool} or may be used as a reference to
  2695. automatically or implicitly exported symbols.
  2696. [This option is specific to the i386 PE targeted port of the linker]
  2697. @cindex DLLs, creating
  2698. @kindex --enable-auto-image-base
  2699. @item --enable-auto-image-base
  2700. @itemx --enable-auto-image-base=@var{value}
  2701. Automatically choose the image base for DLLs, optionally starting with base
  2702. @var{value}, unless one is specified using the @code{--image-base} argument.
  2703. By using a hash generated from the dllname to create unique image bases
  2704. for each DLL, in-memory collisions and relocations which can delay program
  2705. execution are avoided.
  2706. [This option is specific to the i386 PE targeted port of the linker]
  2707. @kindex --disable-auto-image-base
  2708. @item --disable-auto-image-base
  2709. Do not automatically generate a unique image base. If there is no
  2710. user-specified image base (@code{--image-base}) then use the platform
  2711. default.
  2712. [This option is specific to the i386 PE targeted port of the linker]
  2713. @cindex DLLs, linking to
  2714. @kindex --dll-search-prefix
  2715. @item --dll-search-prefix @var{string}
  2716. When linking dynamically to a dll without an import library,
  2717. search for @code{<string><basename>.dll} in preference to
  2718. @code{lib<basename>.dll}. This behaviour allows easy distinction
  2719. between DLLs built for the various "subplatforms": native, cygwin,
  2720. uwin, pw, etc. For instance, cygwin DLLs typically use
  2721. @code{--dll-search-prefix=cyg}.
  2722. [This option is specific to the i386 PE targeted port of the linker]
  2723. @kindex --enable-auto-import
  2724. @item --enable-auto-import
  2725. Do sophisticated linking of @code{_symbol} to @code{__imp__symbol} for
  2726. DATA imports from DLLs, thus making it possible to bypass the dllimport
  2727. mechanism on the user side and to reference unmangled symbol names.
  2728. [This option is specific to the i386 PE targeted port of the linker]
  2729. The following remarks pertain to the original implementation of the
  2730. feature and are obsolete nowadays for Cygwin and MinGW targets.
  2731. Note: Use of the 'auto-import' extension will cause the text section
  2732. of the image file to be made writable. This does not conform to the
  2733. PE-COFF format specification published by Microsoft.
  2734. Note - use of the 'auto-import' extension will also cause read only
  2735. data which would normally be placed into the .rdata section to be
  2736. placed into the .data section instead. This is in order to work
  2737. around a problem with consts that is described here:
  2738. http://www.cygwin.com/ml/cygwin/2004-09/msg01101.html
  2739. Using 'auto-import' generally will 'just work' -- but sometimes you may
  2740. see this message:
  2741. "variable '<var>' can't be auto-imported. Please read the
  2742. documentation for ld's @code{--enable-auto-import} for details."
  2743. This message occurs when some (sub)expression accesses an address
  2744. ultimately given by the sum of two constants (Win32 import tables only
  2745. allow one). Instances where this may occur include accesses to member
  2746. fields of struct variables imported from a DLL, as well as using a
  2747. constant index into an array variable imported from a DLL. Any
  2748. multiword variable (arrays, structs, long long, etc) may trigger
  2749. this error condition. However, regardless of the exact data type
  2750. of the offending exported variable, ld will always detect it, issue
  2751. the warning, and exit.
  2752. There are several ways to address this difficulty, regardless of the
  2753. data type of the exported variable:
  2754. One way is to use --enable-runtime-pseudo-reloc switch. This leaves the task
  2755. of adjusting references in your client code for runtime environment, so
  2756. this method works only when runtime environment supports this feature.
  2757. A second solution is to force one of the 'constants' to be a variable --
  2758. that is, unknown and un-optimizable at compile time. For arrays,
  2759. there are two possibilities: a) make the indexee (the array's address)
  2760. a variable, or b) make the 'constant' index a variable. Thus:
  2761. @example
  2762. extern type extern_array[];
  2763. extern_array[1] -->
  2764. @{ volatile type *t=extern_array; t[1] @}
  2765. @end example
  2766. or
  2767. @example
  2768. extern type extern_array[];
  2769. extern_array[1] -->
  2770. @{ volatile int t=1; extern_array[t] @}
  2771. @end example
  2772. For structs (and most other multiword data types) the only option
  2773. is to make the struct itself (or the long long, or the ...) variable:
  2774. @example
  2775. extern struct s extern_struct;
  2776. extern_struct.field -->
  2777. @{ volatile struct s *t=&extern_struct; t->field @}
  2778. @end example
  2779. or
  2780. @example
  2781. extern long long extern_ll;
  2782. extern_ll -->
  2783. @{ volatile long long * local_ll=&extern_ll; *local_ll @}
  2784. @end example
  2785. A third method of dealing with this difficulty is to abandon
  2786. 'auto-import' for the offending symbol and mark it with
  2787. @code{__declspec(dllimport)}. However, in practice that
  2788. requires using compile-time #defines to indicate whether you are
  2789. building a DLL, building client code that will link to the DLL, or
  2790. merely building/linking to a static library. In making the choice
  2791. between the various methods of resolving the 'direct address with
  2792. constant offset' problem, you should consider typical real-world usage:
  2793. Original:
  2794. @example
  2795. --foo.h
  2796. extern int arr[];
  2797. --foo.c
  2798. #include "foo.h"
  2799. void main(int argc, char **argv)@{
  2800. printf("%d\n",arr[1]);
  2801. @}
  2802. @end example
  2803. Solution 1:
  2804. @example
  2805. --foo.h
  2806. extern int arr[];
  2807. --foo.c
  2808. #include "foo.h"
  2809. void main(int argc, char **argv)@{
  2810. /* This workaround is for win32 and cygwin; do not "optimize" */
  2811. volatile int *parr = arr;
  2812. printf("%d\n",parr[1]);
  2813. @}
  2814. @end example
  2815. Solution 2:
  2816. @example
  2817. --foo.h
  2818. /* Note: auto-export is assumed (no __declspec(dllexport)) */
  2819. #if (defined(_WIN32) || defined(__CYGWIN__)) && \
  2820. !(defined(FOO_BUILD_DLL) || defined(FOO_STATIC))
  2821. #define FOO_IMPORT __declspec(dllimport)
  2822. #else
  2823. #define FOO_IMPORT
  2824. #endif
  2825. extern FOO_IMPORT int arr[];
  2826. --foo.c
  2827. #include "foo.h"
  2828. void main(int argc, char **argv)@{
  2829. printf("%d\n",arr[1]);
  2830. @}
  2831. @end example
  2832. A fourth way to avoid this problem is to re-code your
  2833. library to use a functional interface rather than a data interface
  2834. for the offending variables (e.g. set_foo() and get_foo() accessor
  2835. functions).
  2836. @kindex --disable-auto-import
  2837. @item --disable-auto-import
  2838. Do not attempt to do sophisticated linking of @code{_symbol} to
  2839. @code{__imp__symbol} for DATA imports from DLLs.
  2840. [This option is specific to the i386 PE targeted port of the linker]
  2841. @kindex --enable-runtime-pseudo-reloc
  2842. @item --enable-runtime-pseudo-reloc
  2843. If your code contains expressions described in --enable-auto-import section,
  2844. that is, DATA imports from DLL with non-zero offset, this switch will create
  2845. a vector of 'runtime pseudo relocations' which can be used by runtime
  2846. environment to adjust references to such data in your client code.
  2847. [This option is specific to the i386 PE targeted port of the linker]
  2848. @kindex --disable-runtime-pseudo-reloc
  2849. @item --disable-runtime-pseudo-reloc
  2850. Do not create pseudo relocations for non-zero offset DATA imports from DLLs.
  2851. [This option is specific to the i386 PE targeted port of the linker]
  2852. @kindex --enable-extra-pe-debug
  2853. @item --enable-extra-pe-debug
  2854. Show additional debug info related to auto-import symbol thunking.
  2855. [This option is specific to the i386 PE targeted port of the linker]
  2856. @kindex --section-alignment
  2857. @item --section-alignment
  2858. Sets the section alignment. Sections in memory will always begin at
  2859. addresses which are a multiple of this number. Defaults to 0x1000.
  2860. [This option is specific to the i386 PE targeted port of the linker]
  2861. @cindex stack size
  2862. @kindex --stack
  2863. @item --stack @var{reserve}
  2864. @itemx --stack @var{reserve},@var{commit}
  2865. Specify the number of bytes of memory to reserve (and optionally commit)
  2866. to be used as stack for this program. The default is 2MB reserved, 4K
  2867. committed.
  2868. [This option is specific to the i386 PE targeted port of the linker]
  2869. @kindex --subsystem
  2870. @item --subsystem @var{which}
  2871. @itemx --subsystem @var{which}:@var{major}
  2872. @itemx --subsystem @var{which}:@var{major}.@var{minor}
  2873. Specifies the subsystem under which your program will execute. The
  2874. legal values for @var{which} are @code{native}, @code{windows},
  2875. @code{console}, @code{posix}, and @code{xbox}. You may optionally set
  2876. the subsystem version also. Numeric values are also accepted for
  2877. @var{which}.
  2878. [This option is specific to the i386 PE targeted port of the linker]
  2879. The following options set flags in the @code{DllCharacteristics} field
  2880. of the PE file header:
  2881. [These options are specific to PE targeted ports of the linker]
  2882. @kindex --high-entropy-va
  2883. @item --high-entropy-va
  2884. @itemx --disable-high-entropy-va
  2885. Image is compatible with 64-bit address space layout randomization
  2886. (ASLR). This option is enabled by default for 64-bit PE images.
  2887. This option also implies @option{--dynamicbase} and
  2888. @option{--enable-reloc-section}.
  2889. @kindex --dynamicbase
  2890. @item --dynamicbase
  2891. @itemx --disable-dynamicbase
  2892. The image base address may be relocated using address space layout
  2893. randomization (ASLR). This feature was introduced with MS Windows
  2894. Vista for i386 PE targets. This option is enabled by default but
  2895. can be disabled via the @option{--disable-dynamicbase} option.
  2896. This option also implies @option{--enable-reloc-section}.
  2897. @kindex --forceinteg
  2898. @item --forceinteg
  2899. @itemx --disable-forceinteg
  2900. Code integrity checks are enforced. This option is disabled by
  2901. default.
  2902. @kindex --nxcompat
  2903. @item --nxcompat
  2904. @item --disable-nxcompat
  2905. The image is compatible with the Data Execution Prevention.
  2906. This feature was introduced with MS Windows XP SP2 for i386 PE
  2907. targets. The option is enabled by default.
  2908. @kindex --no-isolation
  2909. @item --no-isolation
  2910. @itemx --disable-no-isolation
  2911. Although the image understands isolation, do not isolate the image.
  2912. This option is disabled by default.
  2913. @kindex --no-seh
  2914. @item --no-seh
  2915. @itemx --disable-no-seh
  2916. The image does not use SEH. No SE handler may be called from
  2917. this image. This option is disabled by default.
  2918. @kindex --no-bind
  2919. @item --no-bind
  2920. @itemx --disable-no-bind
  2921. Do not bind this image. This option is disabled by default.
  2922. @kindex --wdmdriver
  2923. @item --wdmdriver
  2924. @itemx --disable-wdmdriver
  2925. The driver uses the MS Windows Driver Model. This option is disabled
  2926. by default.
  2927. @kindex --tsaware
  2928. @item --tsaware
  2929. @itemx --disable-tsaware
  2930. The image is Terminal Server aware. This option is disabled by
  2931. default.
  2932. @kindex --insert-timestamp
  2933. @item --insert-timestamp
  2934. @itemx --no-insert-timestamp
  2935. Insert a real timestamp into the image. This is the default behaviour
  2936. as it matches legacy code and it means that the image will work with
  2937. other, proprietary tools. The problem with this default is that it
  2938. will result in slightly different images being produced each time the
  2939. same sources are linked. The option @option{--no-insert-timestamp}
  2940. can be used to insert a zero value for the timestamp, this ensuring
  2941. that binaries produced from identical sources will compare
  2942. identically.
  2943. @kindex --enable-reloc-section
  2944. @item --enable-reloc-section
  2945. @itemx --disable-reloc-section
  2946. Create the base relocation table, which is necessary if the image
  2947. is loaded at a different image base than specified in the PE header.
  2948. This option is enabled by default.
  2949. @end table
  2950. @c man end
  2951. @ifset C6X
  2952. @subsection Options specific to C6X uClinux targets
  2953. @c man begin OPTIONS
  2954. The C6X uClinux target uses a binary format called DSBT to support shared
  2955. libraries. Each shared library in the system needs to have a unique index;
  2956. all executables use an index of 0.
  2957. @table @gcctabopt
  2958. @kindex --dsbt-size
  2959. @item --dsbt-size @var{size}
  2960. This option sets the number of entries in the DSBT of the current executable
  2961. or shared library to @var{size}. The default is to create a table with 64
  2962. entries.
  2963. @kindex --dsbt-index
  2964. @item --dsbt-index @var{index}
  2965. This option sets the DSBT index of the current executable or shared library
  2966. to @var{index}. The default is 0, which is appropriate for generating
  2967. executables. If a shared library is generated with a DSBT index of 0, the
  2968. @code{R_C6000_DSBT_INDEX} relocs are copied into the output file.
  2969. @kindex --no-merge-exidx-entries
  2970. The @samp{--no-merge-exidx-entries} switch disables the merging of adjacent
  2971. exidx entries in frame unwind info.
  2972. @end table
  2973. @c man end
  2974. @end ifset
  2975. @ifset CSKY
  2976. @subsection Options specific to C-SKY targets
  2977. @c man begin OPTIONS
  2978. @table @gcctabopt
  2979. @kindex --branch-stub on C-SKY
  2980. @item --branch-stub
  2981. This option enables linker branch relaxation by inserting branch stub
  2982. sections when needed to extend the range of branches. This option is
  2983. usually not required since C-SKY supports branch and call instructions that
  2984. can access the full memory range and branch relaxation is normally handled by
  2985. the compiler or assembler.
  2986. @kindex --stub-group-size on C-SKY
  2987. @item --stub-group-size=@var{N}
  2988. This option allows finer control of linker branch stub creation.
  2989. It sets the maximum size of a group of input sections that can
  2990. be handled by one stub section. A negative value of @var{N} locates
  2991. stub sections after their branches, while a positive value allows stub
  2992. sections to appear either before or after the branches. Values of
  2993. @samp{1} or @samp{-1} indicate that the
  2994. linker should choose suitable defaults.
  2995. @end table
  2996. @c man end
  2997. @end ifset
  2998. @ifset M68HC11
  2999. @subsection Options specific to Motorola 68HC11 and 68HC12 targets
  3000. @c man begin OPTIONS
  3001. The 68HC11 and 68HC12 linkers support specific options to control the
  3002. memory bank switching mapping and trampoline code generation.
  3003. @table @gcctabopt
  3004. @kindex --no-trampoline
  3005. @item --no-trampoline
  3006. This option disables the generation of trampoline. By default a trampoline
  3007. is generated for each far function which is called using a @code{jsr}
  3008. instruction (this happens when a pointer to a far function is taken).
  3009. @kindex --bank-window
  3010. @item --bank-window @var{name}
  3011. This option indicates to the linker the name of the memory region in
  3012. the @samp{MEMORY} specification that describes the memory bank window.
  3013. The definition of such region is then used by the linker to compute
  3014. paging and addresses within the memory window.
  3015. @end table
  3016. @c man end
  3017. @end ifset
  3018. @ifset M68K
  3019. @subsection Options specific to Motorola 68K target
  3020. @c man begin OPTIONS
  3021. The following options are supported to control handling of GOT generation
  3022. when linking for 68K targets.
  3023. @table @gcctabopt
  3024. @kindex --got
  3025. @item --got=@var{type}
  3026. This option tells the linker which GOT generation scheme to use.
  3027. @var{type} should be one of @samp{single}, @samp{negative},
  3028. @samp{multigot} or @samp{target}. For more information refer to the
  3029. Info entry for @file{ld}.
  3030. @end table
  3031. @c man end
  3032. @end ifset
  3033. @ifset MIPS
  3034. @subsection Options specific to MIPS targets
  3035. @c man begin OPTIONS
  3036. The following options are supported to control microMIPS instruction
  3037. generation and branch relocation checks for ISA mode transitions when
  3038. linking for MIPS targets.
  3039. @table @gcctabopt
  3040. @kindex --insn32
  3041. @item --insn32
  3042. @kindex --no-insn32
  3043. @itemx --no-insn32
  3044. These options control the choice of microMIPS instructions used in code
  3045. generated by the linker, such as that in the PLT or lazy binding stubs,
  3046. or in relaxation. If @samp{--insn32} is used, then the linker only uses
  3047. 32-bit instruction encodings. By default or if @samp{--no-insn32} is
  3048. used, all instruction encodings are used, including 16-bit ones where
  3049. possible.
  3050. @kindex --ignore-branch-isa
  3051. @item --ignore-branch-isa
  3052. @kindex --no-ignore-branch-isa
  3053. @itemx --no-ignore-branch-isa
  3054. These options control branch relocation checks for invalid ISA mode
  3055. transitions. If @samp{--ignore-branch-isa} is used, then the linker
  3056. accepts any branch relocations and any ISA mode transition required
  3057. is lost in relocation calculation, except for some cases of @code{BAL}
  3058. instructions which meet relaxation conditions and are converted to
  3059. equivalent @code{JALX} instructions as the associated relocation is
  3060. calculated. By default or if @samp{--no-ignore-branch-isa} is used
  3061. a check is made causing the loss of an ISA mode transition to produce
  3062. an error.
  3063. @kindex --compact-branches
  3064. @item --compact-branches
  3065. @kindex --no-compact-branches
  3066. @itemx --no-compact-branches
  3067. These options control the generation of compact instructions by the linker
  3068. in the PLT entries for MIPS R6.
  3069. @end table
  3070. @c man end
  3071. @end ifset
  3072. @ifset PDP11
  3073. @subsection Options specific to PDP11 targets
  3074. @c man begin OPTIONS
  3075. For the pdp11-aout target, three variants of the output format can be
  3076. produced as selected by the following options. The default variant
  3077. for pdp11-aout is the @samp{--omagic} option, whereas for other
  3078. targets @samp{--nmagic} is the default. The @samp{--imagic} option is
  3079. defined only for the pdp11-aout target, while the others are described
  3080. here as they apply to the pdp11-aout target.
  3081. @table @gcctabopt
  3082. @kindex -N
  3083. @item -N
  3084. @kindex --omagic
  3085. @itemx --omagic
  3086. Mark the output as @code{OMAGIC} (0407) in the @file{a.out} header to
  3087. indicate that the text segment is not to be write-protected and
  3088. shared. Since the text and data sections are both readable and
  3089. writable, the data section is allocated immediately contiguous after
  3090. the text segment. This is the oldest format for PDP11 executable
  3091. programs and is the default for @command{ld} on PDP11 Unix systems
  3092. from the beginning through 2.11BSD.
  3093. @kindex -n
  3094. @item -n
  3095. @kindex --nmagic
  3096. @itemx --nmagic
  3097. Mark the output as @code{NMAGIC} (0410) in the @file{a.out} header to
  3098. indicate that when the output file is executed, the text portion will
  3099. be read-only and shareable among all processes executing the same
  3100. file. This involves moving the data areas up to the first possible 8K
  3101. byte page boundary following the end of the text. This option creates
  3102. a @emph{pure executable} format.
  3103. @kindex -z
  3104. @item -z
  3105. @kindex --imagic
  3106. @itemx --imagic
  3107. Mark the output as @code{IMAGIC} (0411) in the @file{a.out} header to
  3108. indicate that when the output file is executed, the program text and
  3109. data areas will be loaded into separate address spaces using the split
  3110. instruction and data space feature of the memory management unit in
  3111. larger models of the PDP11. This doubles the address space available
  3112. to the program. The text segment is again pure, write-protected, and
  3113. shareable. The only difference in the output format between this
  3114. option and the others, besides the magic number, is that both the text
  3115. and data sections start at location 0. The @samp{-z} option selected
  3116. this format in 2.11BSD. This option creates a @emph{separate
  3117. executable} format.
  3118. @kindex --no-omagic
  3119. @item --no-omagic
  3120. Equivalent to @samp{--nmagic} for pdp11-aout.
  3121. @end table
  3122. @c man end
  3123. @end ifset
  3124. @ifset UsesEnvVars
  3125. @node Environment
  3126. @section Environment Variables
  3127. @c man begin ENVIRONMENT
  3128. You can change the behaviour of @command{ld} with the environment variables
  3129. @ifclear SingleFormat
  3130. @code{GNUTARGET},
  3131. @end ifclear
  3132. @code{LDEMULATION} and @code{COLLECT_NO_DEMANGLE}.
  3133. @ifclear SingleFormat
  3134. @kindex GNUTARGET
  3135. @cindex default input format
  3136. @code{GNUTARGET} determines the input-file object format if you don't
  3137. use @samp{-b} (or its synonym @samp{--format}). Its value should be one
  3138. of the BFD names for an input format (@pxref{BFD}). If there is no
  3139. @code{GNUTARGET} in the environment, @command{ld} uses the natural format
  3140. of the target. If @code{GNUTARGET} is set to @code{default} then BFD
  3141. attempts to discover the input format by examining binary input files;
  3142. this method often succeeds, but there are potential ambiguities, since
  3143. there is no method of ensuring that the magic number used to specify
  3144. object-file formats is unique. However, the configuration procedure for
  3145. BFD on each system places the conventional format for that system first
  3146. in the search-list, so ambiguities are resolved in favor of convention.
  3147. @end ifclear
  3148. @kindex LDEMULATION
  3149. @cindex default emulation
  3150. @cindex emulation, default
  3151. @code{LDEMULATION} determines the default emulation if you don't use the
  3152. @samp{-m} option. The emulation can affect various aspects of linker
  3153. behaviour, particularly the default linker script. You can list the
  3154. available emulations with the @samp{--verbose} or @samp{-V} options. If
  3155. the @samp{-m} option is not used, and the @code{LDEMULATION} environment
  3156. variable is not defined, the default emulation depends upon how the
  3157. linker was configured.
  3158. @kindex COLLECT_NO_DEMANGLE
  3159. @cindex demangling, default
  3160. Normally, the linker will default to demangling symbols. However, if
  3161. @code{COLLECT_NO_DEMANGLE} is set in the environment, then it will
  3162. default to not demangling symbols. This environment variable is used in
  3163. a similar fashion by the @code{gcc} linker wrapper program. The default
  3164. may be overridden by the @samp{--demangle} and @samp{--no-demangle}
  3165. options.
  3166. @c man end
  3167. @end ifset
  3168. @node Scripts
  3169. @chapter Linker Scripts
  3170. @cindex scripts
  3171. @cindex linker scripts
  3172. @cindex command files
  3173. Every link is controlled by a @dfn{linker script}. This script is
  3174. written in the linker command language.
  3175. The main purpose of the linker script is to describe how the sections in
  3176. the input files should be mapped into the output file, and to control
  3177. the memory layout of the output file. Most linker scripts do nothing
  3178. more than this. However, when necessary, the linker script can also
  3179. direct the linker to perform many other operations, using the commands
  3180. described below.
  3181. The linker always uses a linker script. If you do not supply one
  3182. yourself, the linker will use a default script that is compiled into the
  3183. linker executable. You can use the @samp{--verbose} command-line option
  3184. to display the default linker script. Certain command-line options,
  3185. such as @samp{-r} or @samp{-N}, will affect the default linker script.
  3186. You may supply your own linker script by using the @samp{-T} command
  3187. line option. When you do this, your linker script will replace the
  3188. default linker script.
  3189. You may also use linker scripts implicitly by naming them as input files
  3190. to the linker, as though they were files to be linked. @xref{Implicit
  3191. Linker Scripts}.
  3192. @menu
  3193. * Basic Script Concepts:: Basic Linker Script Concepts
  3194. * Script Format:: Linker Script Format
  3195. * Simple Example:: Simple Linker Script Example
  3196. * Simple Commands:: Simple Linker Script Commands
  3197. * Assignments:: Assigning Values to Symbols
  3198. * SECTIONS:: SECTIONS Command
  3199. * MEMORY:: MEMORY Command
  3200. * PHDRS:: PHDRS Command
  3201. * VERSION:: VERSION Command
  3202. * Expressions:: Expressions in Linker Scripts
  3203. * Implicit Linker Scripts:: Implicit Linker Scripts
  3204. @end menu
  3205. @node Basic Script Concepts
  3206. @section Basic Linker Script Concepts
  3207. @cindex linker script concepts
  3208. We need to define some basic concepts and vocabulary in order to
  3209. describe the linker script language.
  3210. The linker combines input files into a single output file. The output
  3211. file and each input file are in a special data format known as an
  3212. @dfn{object file format}. Each file is called an @dfn{object file}.
  3213. The output file is often called an @dfn{executable}, but for our
  3214. purposes we will also call it an object file. Each object file has,
  3215. among other things, a list of @dfn{sections}. We sometimes refer to a
  3216. section in an input file as an @dfn{input section}; similarly, a section
  3217. in the output file is an @dfn{output section}.
  3218. Each section in an object file has a name and a size. Most sections
  3219. also have an associated block of data, known as the @dfn{section
  3220. contents}. A section may be marked as @dfn{loadable}, which means that
  3221. the contents should be loaded into memory when the output file is run.
  3222. A section with no contents may be @dfn{allocatable}, which means that an
  3223. area in memory should be set aside, but nothing in particular should be
  3224. loaded there (in some cases this memory must be zeroed out). A section
  3225. which is neither loadable nor allocatable typically contains some sort
  3226. of debugging information.
  3227. Every loadable or allocatable output section has two addresses. The
  3228. first is the @dfn{VMA}, or virtual memory address. This is the address
  3229. the section will have when the output file is run. The second is the
  3230. @dfn{LMA}, or load memory address. This is the address at which the
  3231. section will be loaded. In most cases the two addresses will be the
  3232. same. An example of when they might be different is when a data section
  3233. is loaded into ROM, and then copied into RAM when the program starts up
  3234. (this technique is often used to initialize global variables in a ROM
  3235. based system). In this case the ROM address would be the LMA, and the
  3236. RAM address would be the VMA.
  3237. You can see the sections in an object file by using the @code{objdump}
  3238. program with the @samp{-h} option.
  3239. Every object file also has a list of @dfn{symbols}, known as the
  3240. @dfn{symbol table}. A symbol may be defined or undefined. Each symbol
  3241. has a name, and each defined symbol has an address, among other
  3242. information. If you compile a C or C++ program into an object file, you
  3243. will get a defined symbol for every defined function and global or
  3244. static variable. Every undefined function or global variable which is
  3245. referenced in the input file will become an undefined symbol.
  3246. You can see the symbols in an object file by using the @code{nm}
  3247. program, or by using the @code{objdump} program with the @samp{-t}
  3248. option.
  3249. @node Script Format
  3250. @section Linker Script Format
  3251. @cindex linker script format
  3252. Linker scripts are text files.
  3253. You write a linker script as a series of commands. Each command is
  3254. either a keyword, possibly followed by arguments, or an assignment to a
  3255. symbol. You may separate commands using semicolons. Whitespace is
  3256. generally ignored.
  3257. Strings such as file or format names can normally be entered directly.
  3258. If the file name contains a character such as a comma which would
  3259. otherwise serve to separate file names, you may put the file name in
  3260. double quotes. There is no way to use a double quote character in a
  3261. file name.
  3262. You may include comments in linker scripts just as in C, delimited by
  3263. @samp{/*} and @samp{*/}. As in C, comments are syntactically equivalent
  3264. to whitespace.
  3265. @node Simple Example
  3266. @section Simple Linker Script Example
  3267. @cindex linker script example
  3268. @cindex example of linker script
  3269. Many linker scripts are fairly simple.
  3270. The simplest possible linker script has just one command:
  3271. @samp{SECTIONS}. You use the @samp{SECTIONS} command to describe the
  3272. memory layout of the output file.
  3273. The @samp{SECTIONS} command is a powerful command. Here we will
  3274. describe a simple use of it. Let's assume your program consists only of
  3275. code, initialized data, and uninitialized data. These will be in the
  3276. @samp{.text}, @samp{.data}, and @samp{.bss} sections, respectively.
  3277. Let's assume further that these are the only sections which appear in
  3278. your input files.
  3279. For this example, let's say that the code should be loaded at address
  3280. 0x10000, and that the data should start at address 0x8000000. Here is a
  3281. linker script which will do that:
  3282. @smallexample
  3283. SECTIONS
  3284. @{
  3285. . = 0x10000;
  3286. .text : @{ *(.text) @}
  3287. . = 0x8000000;
  3288. .data : @{ *(.data) @}
  3289. .bss : @{ *(.bss) @}
  3290. @}
  3291. @end smallexample
  3292. You write the @samp{SECTIONS} command as the keyword @samp{SECTIONS},
  3293. followed by a series of symbol assignments and output section
  3294. descriptions enclosed in curly braces.
  3295. The first line inside the @samp{SECTIONS} command of the above example
  3296. sets the value of the special symbol @samp{.}, which is the location
  3297. counter. If you do not specify the address of an output section in some
  3298. other way (other ways are described later), the address is set from the
  3299. current value of the location counter. The location counter is then
  3300. incremented by the size of the output section. At the start of the
  3301. @samp{SECTIONS} command, the location counter has the value @samp{0}.
  3302. The second line defines an output section, @samp{.text}. The colon is
  3303. required syntax which may be ignored for now. Within the curly braces
  3304. after the output section name, you list the names of the input sections
  3305. which should be placed into this output section. The @samp{*} is a
  3306. wildcard which matches any file name. The expression @samp{*(.text)}
  3307. means all @samp{.text} input sections in all input files.
  3308. Since the location counter is @samp{0x10000} when the output section
  3309. @samp{.text} is defined, the linker will set the address of the
  3310. @samp{.text} section in the output file to be @samp{0x10000}.
  3311. The remaining lines define the @samp{.data} and @samp{.bss} sections in
  3312. the output file. The linker will place the @samp{.data} output section
  3313. at address @samp{0x8000000}. After the linker places the @samp{.data}
  3314. output section, the value of the location counter will be
  3315. @samp{0x8000000} plus the size of the @samp{.data} output section. The
  3316. effect is that the linker will place the @samp{.bss} output section
  3317. immediately after the @samp{.data} output section in memory.
  3318. The linker will ensure that each output section has the required
  3319. alignment, by increasing the location counter if necessary. In this
  3320. example, the specified addresses for the @samp{.text} and @samp{.data}
  3321. sections will probably satisfy any alignment constraints, but the linker
  3322. may have to create a small gap between the @samp{.data} and @samp{.bss}
  3323. sections.
  3324. That's it! That's a simple and complete linker script.
  3325. @node Simple Commands
  3326. @section Simple Linker Script Commands
  3327. @cindex linker script simple commands
  3328. In this section we describe the simple linker script commands.
  3329. @menu
  3330. * Entry Point:: Setting the entry point
  3331. * File Commands:: Commands dealing with files
  3332. @ifclear SingleFormat
  3333. * Format Commands:: Commands dealing with object file formats
  3334. @end ifclear
  3335. * REGION_ALIAS:: Assign alias names to memory regions
  3336. * Miscellaneous Commands:: Other linker script commands
  3337. @end menu
  3338. @node Entry Point
  3339. @subsection Setting the Entry Point
  3340. @kindex ENTRY(@var{symbol})
  3341. @cindex start of execution
  3342. @cindex first instruction
  3343. @cindex entry point
  3344. The first instruction to execute in a program is called the @dfn{entry
  3345. point}. You can use the @code{ENTRY} linker script command to set the
  3346. entry point. The argument is a symbol name:
  3347. @smallexample
  3348. ENTRY(@var{symbol})
  3349. @end smallexample
  3350. There are several ways to set the entry point. The linker will set the
  3351. entry point by trying each of the following methods in order, and
  3352. stopping when one of them succeeds:
  3353. @itemize @bullet
  3354. @item
  3355. the @samp{-e} @var{entry} command-line option;
  3356. @item
  3357. the @code{ENTRY(@var{symbol})} command in a linker script;
  3358. @item
  3359. the value of a target-specific symbol, if it is defined; For many
  3360. targets this is @code{start}, but PE- and BeOS-based systems for example
  3361. check a list of possible entry symbols, matching the first one found.
  3362. @item
  3363. the address of the first byte of the code section, if present and an
  3364. executable is being created - the code section is usually
  3365. @samp{.text}, but can be something else;
  3366. @item
  3367. The address @code{0}.
  3368. @end itemize
  3369. @node File Commands
  3370. @subsection Commands Dealing with Files
  3371. @cindex linker script file commands
  3372. Several linker script commands deal with files.
  3373. @table @code
  3374. @item INCLUDE @var{filename}
  3375. @kindex INCLUDE @var{filename}
  3376. @cindex including a linker script
  3377. Include the linker script @var{filename} at this point. The file will
  3378. be searched for in the current directory, and in any directory specified
  3379. with the @option{-L} option. You can nest calls to @code{INCLUDE} up to
  3380. 10 levels deep.
  3381. You can place @code{INCLUDE} directives at the top level, in @code{MEMORY} or
  3382. @code{SECTIONS} commands, or in output section descriptions.
  3383. @item INPUT(@var{file}, @var{file}, @dots{})
  3384. @itemx INPUT(@var{file} @var{file} @dots{})
  3385. @kindex INPUT(@var{files})
  3386. @cindex input files in linker scripts
  3387. @cindex input object files in linker scripts
  3388. @cindex linker script input object files
  3389. The @code{INPUT} command directs the linker to include the named files
  3390. in the link, as though they were named on the command line.
  3391. For example, if you always want to include @file{subr.o} any time you do
  3392. a link, but you can't be bothered to put it on every link command line,
  3393. then you can put @samp{INPUT (subr.o)} in your linker script.
  3394. In fact, if you like, you can list all of your input files in the linker
  3395. script, and then invoke the linker with nothing but a @samp{-T} option.
  3396. In case a @dfn{sysroot prefix} is configured, and the filename starts
  3397. with the @samp{/} character, and the script being processed was
  3398. located inside the @dfn{sysroot prefix}, the filename will be looked
  3399. for in the @dfn{sysroot prefix}. The @dfn{sysroot prefix} can also be forced by specifying
  3400. @code{=} as the first character in the filename path, or prefixing the
  3401. filename path with @code{$SYSROOT}. See also the description of
  3402. @samp{-L} in @ref{Options,,Command-line Options}.
  3403. If a @dfn{sysroot prefix} is not used then the linker will try to open
  3404. the file in the directory containing the linker script. If it is not
  3405. found the linker will then search the current directory. If it is still
  3406. not found the linker will search through the archive library search
  3407. path.
  3408. If you use @samp{INPUT (-l@var{file})}, @command{ld} will transform the
  3409. name to @code{lib@var{file}.a}, as with the command-line argument
  3410. @samp{-l}.
  3411. When you use the @code{INPUT} command in an implicit linker script, the
  3412. files will be included in the link at the point at which the linker
  3413. script file is included. This can affect archive searching.
  3414. @item GROUP(@var{file}, @var{file}, @dots{})
  3415. @itemx GROUP(@var{file} @var{file} @dots{})
  3416. @kindex GROUP(@var{files})
  3417. @cindex grouping input files
  3418. The @code{GROUP} command is like @code{INPUT}, except that the named
  3419. files should all be archives, and they are searched repeatedly until no
  3420. new undefined references are created. See the description of @samp{-(}
  3421. in @ref{Options,,Command-line Options}.
  3422. @item AS_NEEDED(@var{file}, @var{file}, @dots{})
  3423. @itemx AS_NEEDED(@var{file} @var{file} @dots{})
  3424. @kindex AS_NEEDED(@var{files})
  3425. This construct can appear only inside of the @code{INPUT} or @code{GROUP}
  3426. commands, among other filenames. The files listed will be handled
  3427. as if they appear directly in the @code{INPUT} or @code{GROUP} commands,
  3428. with the exception of ELF shared libraries, that will be added only
  3429. when they are actually needed. This construct essentially enables
  3430. @option{--as-needed} option for all the files listed inside of it
  3431. and restores previous @option{--as-needed} resp. @option{--no-as-needed}
  3432. setting afterwards.
  3433. @item OUTPUT(@var{filename})
  3434. @kindex OUTPUT(@var{filename})
  3435. @cindex output file name in linker script
  3436. The @code{OUTPUT} command names the output file. Using
  3437. @code{OUTPUT(@var{filename})} in the linker script is exactly like using
  3438. @samp{-o @var{filename}} on the command line (@pxref{Options,,Command
  3439. Line Options}). If both are used, the command-line option takes
  3440. precedence.
  3441. You can use the @code{OUTPUT} command to define a default name for the
  3442. output file other than the usual default of @file{a.out}.
  3443. @item SEARCH_DIR(@var{path})
  3444. @kindex SEARCH_DIR(@var{path})
  3445. @cindex library search path in linker script
  3446. @cindex archive search path in linker script
  3447. @cindex search path in linker script
  3448. The @code{SEARCH_DIR} command adds @var{path} to the list of paths where
  3449. @command{ld} looks for archive libraries. Using
  3450. @code{SEARCH_DIR(@var{path})} is exactly like using @samp{-L @var{path}}
  3451. on the command line (@pxref{Options,,Command-line Options}). If both
  3452. are used, then the linker will search both paths. Paths specified using
  3453. the command-line option are searched first.
  3454. @item STARTUP(@var{filename})
  3455. @kindex STARTUP(@var{filename})
  3456. @cindex first input file
  3457. The @code{STARTUP} command is just like the @code{INPUT} command, except
  3458. that @var{filename} will become the first input file to be linked, as
  3459. though it were specified first on the command line. This may be useful
  3460. when using a system in which the entry point is always the start of the
  3461. first file.
  3462. @end table
  3463. @ifclear SingleFormat
  3464. @node Format Commands
  3465. @subsection Commands Dealing with Object File Formats
  3466. A couple of linker script commands deal with object file formats.
  3467. @table @code
  3468. @item OUTPUT_FORMAT(@var{bfdname})
  3469. @itemx OUTPUT_FORMAT(@var{default}, @var{big}, @var{little})
  3470. @kindex OUTPUT_FORMAT(@var{bfdname})
  3471. @cindex output file format in linker script
  3472. The @code{OUTPUT_FORMAT} command names the BFD format to use for the
  3473. output file (@pxref{BFD}). Using @code{OUTPUT_FORMAT(@var{bfdname})} is
  3474. exactly like using @samp{--oformat @var{bfdname}} on the command line
  3475. (@pxref{Options,,Command-line Options}). If both are used, the command
  3476. line option takes precedence.
  3477. You can use @code{OUTPUT_FORMAT} with three arguments to use different
  3478. formats based on the @samp{-EB} and @samp{-EL} command-line options.
  3479. This permits the linker script to set the output format based on the
  3480. desired endianness.
  3481. If neither @samp{-EB} nor @samp{-EL} are used, then the output format
  3482. will be the first argument, @var{default}. If @samp{-EB} is used, the
  3483. output format will be the second argument, @var{big}. If @samp{-EL} is
  3484. used, the output format will be the third argument, @var{little}.
  3485. For example, the default linker script for the MIPS ELF target uses this
  3486. command:
  3487. @smallexample
  3488. OUTPUT_FORMAT(elf32-bigmips, elf32-bigmips, elf32-littlemips)
  3489. @end smallexample
  3490. This says that the default format for the output file is
  3491. @samp{elf32-bigmips}, but if the user uses the @samp{-EL} command-line
  3492. option, the output file will be created in the @samp{elf32-littlemips}
  3493. format.
  3494. @item TARGET(@var{bfdname})
  3495. @kindex TARGET(@var{bfdname})
  3496. @cindex input file format in linker script
  3497. The @code{TARGET} command names the BFD format to use when reading input
  3498. files. It affects subsequent @code{INPUT} and @code{GROUP} commands.
  3499. This command is like using @samp{-b @var{bfdname}} on the command line
  3500. (@pxref{Options,,Command-line Options}). If the @code{TARGET} command
  3501. is used but @code{OUTPUT_FORMAT} is not, then the last @code{TARGET}
  3502. command is also used to set the format for the output file. @xref{BFD}.
  3503. @end table
  3504. @end ifclear
  3505. @node REGION_ALIAS
  3506. @subsection Assign alias names to memory regions
  3507. @kindex REGION_ALIAS(@var{alias}, @var{region})
  3508. @cindex region alias
  3509. @cindex region names
  3510. Alias names can be added to existing memory regions created with the
  3511. @ref{MEMORY} command. Each name corresponds to at most one memory region.
  3512. @smallexample
  3513. REGION_ALIAS(@var{alias}, @var{region})
  3514. @end smallexample
  3515. The @code{REGION_ALIAS} function creates an alias name @var{alias} for the
  3516. memory region @var{region}. This allows a flexible mapping of output sections
  3517. to memory regions. An example follows.
  3518. Suppose we have an application for embedded systems which come with various
  3519. memory storage devices. All have a general purpose, volatile memory @code{RAM}
  3520. that allows code execution or data storage. Some may have a read-only,
  3521. non-volatile memory @code{ROM} that allows code execution and read-only data
  3522. access. The last variant is a read-only, non-volatile memory @code{ROM2} with
  3523. read-only data access and no code execution capability. We have four output
  3524. sections:
  3525. @itemize @bullet
  3526. @item
  3527. @code{.text} program code;
  3528. @item
  3529. @code{.rodata} read-only data;
  3530. @item
  3531. @code{.data} read-write initialized data;
  3532. @item
  3533. @code{.bss} read-write zero initialized data.
  3534. @end itemize
  3535. The goal is to provide a linker command file that contains a system independent
  3536. part defining the output sections and a system dependent part mapping the
  3537. output sections to the memory regions available on the system. Our embedded
  3538. systems come with three different memory setups @code{A}, @code{B} and
  3539. @code{C}:
  3540. @multitable @columnfractions .25 .25 .25 .25
  3541. @item Section @tab Variant A @tab Variant B @tab Variant C
  3542. @item .text @tab RAM @tab ROM @tab ROM
  3543. @item .rodata @tab RAM @tab ROM @tab ROM2
  3544. @item .data @tab RAM @tab RAM/ROM @tab RAM/ROM2
  3545. @item .bss @tab RAM @tab RAM @tab RAM
  3546. @end multitable
  3547. The notation @code{RAM/ROM} or @code{RAM/ROM2} means that this section is
  3548. loaded into region @code{ROM} or @code{ROM2} respectively. Please note that
  3549. the load address of the @code{.data} section starts in all three variants at
  3550. the end of the @code{.rodata} section.
  3551. The base linker script that deals with the output sections follows. It
  3552. includes the system dependent @code{linkcmds.memory} file that describes the
  3553. memory layout:
  3554. @smallexample
  3555. INCLUDE linkcmds.memory
  3556. SECTIONS
  3557. @{
  3558. .text :
  3559. @{
  3560. *(.text)
  3561. @} > REGION_TEXT
  3562. .rodata :
  3563. @{
  3564. *(.rodata)
  3565. rodata_end = .;
  3566. @} > REGION_RODATA
  3567. .data : AT (rodata_end)
  3568. @{
  3569. data_start = .;
  3570. *(.data)
  3571. @} > REGION_DATA
  3572. data_size = SIZEOF(.data);
  3573. data_load_start = LOADADDR(.data);
  3574. .bss :
  3575. @{
  3576. *(.bss)
  3577. @} > REGION_BSS
  3578. @}
  3579. @end smallexample
  3580. Now we need three different @code{linkcmds.memory} files to define memory
  3581. regions and alias names. The content of @code{linkcmds.memory} for the three
  3582. variants @code{A}, @code{B} and @code{C}:
  3583. @table @code
  3584. @item A
  3585. Here everything goes into the @code{RAM}.
  3586. @smallexample
  3587. MEMORY
  3588. @{
  3589. RAM : ORIGIN = 0, LENGTH = 4M
  3590. @}
  3591. REGION_ALIAS("REGION_TEXT", RAM);
  3592. REGION_ALIAS("REGION_RODATA", RAM);
  3593. REGION_ALIAS("REGION_DATA", RAM);
  3594. REGION_ALIAS("REGION_BSS", RAM);
  3595. @end smallexample
  3596. @item B
  3597. Program code and read-only data go into the @code{ROM}. Read-write data goes
  3598. into the @code{RAM}. An image of the initialized data is loaded into the
  3599. @code{ROM} and will be copied during system start into the @code{RAM}.
  3600. @smallexample
  3601. MEMORY
  3602. @{
  3603. ROM : ORIGIN = 0, LENGTH = 3M
  3604. RAM : ORIGIN = 0x10000000, LENGTH = 1M
  3605. @}
  3606. REGION_ALIAS("REGION_TEXT", ROM);
  3607. REGION_ALIAS("REGION_RODATA", ROM);
  3608. REGION_ALIAS("REGION_DATA", RAM);
  3609. REGION_ALIAS("REGION_BSS", RAM);
  3610. @end smallexample
  3611. @item C
  3612. Program code goes into the @code{ROM}. Read-only data goes into the
  3613. @code{ROM2}. Read-write data goes into the @code{RAM}. An image of the
  3614. initialized data is loaded into the @code{ROM2} and will be copied during
  3615. system start into the @code{RAM}.
  3616. @smallexample
  3617. MEMORY
  3618. @{
  3619. ROM : ORIGIN = 0, LENGTH = 2M
  3620. ROM2 : ORIGIN = 0x10000000, LENGTH = 1M
  3621. RAM : ORIGIN = 0x20000000, LENGTH = 1M
  3622. @}
  3623. REGION_ALIAS("REGION_TEXT", ROM);
  3624. REGION_ALIAS("REGION_RODATA", ROM2);
  3625. REGION_ALIAS("REGION_DATA", RAM);
  3626. REGION_ALIAS("REGION_BSS", RAM);
  3627. @end smallexample
  3628. @end table
  3629. It is possible to write a common system initialization routine to copy the
  3630. @code{.data} section from @code{ROM} or @code{ROM2} into the @code{RAM} if
  3631. necessary:
  3632. @smallexample
  3633. #include <string.h>
  3634. extern char data_start [];
  3635. extern char data_size [];
  3636. extern char data_load_start [];
  3637. void copy_data(void)
  3638. @{
  3639. if (data_start != data_load_start)
  3640. @{
  3641. memcpy(data_start, data_load_start, (size_t) data_size);
  3642. @}
  3643. @}
  3644. @end smallexample
  3645. @node Miscellaneous Commands
  3646. @subsection Other Linker Script Commands
  3647. There are a few other linker scripts commands.
  3648. @table @code
  3649. @item ASSERT(@var{exp}, @var{message})
  3650. @kindex ASSERT
  3651. @cindex assertion in linker script
  3652. Ensure that @var{exp} is non-zero. If it is zero, then exit the linker
  3653. with an error code, and print @var{message}.
  3654. Note that assertions are checked before the final stages of linking
  3655. take place. This means that expressions involving symbols PROVIDEd
  3656. inside section definitions will fail if the user has not set values
  3657. for those symbols. The only exception to this rule is PROVIDEd
  3658. symbols that just reference dot. Thus an assertion like this:
  3659. @smallexample
  3660. .stack :
  3661. @{
  3662. PROVIDE (__stack = .);
  3663. PROVIDE (__stack_size = 0x100);
  3664. ASSERT ((__stack > (_end + __stack_size)), "Error: No room left for the stack");
  3665. @}
  3666. @end smallexample
  3667. will fail if @code{__stack_size} is not defined elsewhere. Symbols
  3668. PROVIDEd outside of section definitions are evaluated earlier, so they
  3669. can be used inside ASSERTions. Thus:
  3670. @smallexample
  3671. PROVIDE (__stack_size = 0x100);
  3672. .stack :
  3673. @{
  3674. PROVIDE (__stack = .);
  3675. ASSERT ((__stack > (_end + __stack_size)), "Error: No room left for the stack");
  3676. @}
  3677. @end smallexample
  3678. will work.
  3679. @item EXTERN(@var{symbol} @var{symbol} @dots{})
  3680. @kindex EXTERN
  3681. @cindex undefined symbol in linker script
  3682. Force @var{symbol} to be entered in the output file as an undefined
  3683. symbol. Doing this may, for example, trigger linking of additional
  3684. modules from standard libraries. You may list several @var{symbol}s for
  3685. each @code{EXTERN}, and you may use @code{EXTERN} multiple times. This
  3686. command has the same effect as the @samp{-u} command-line option.
  3687. @item FORCE_COMMON_ALLOCATION
  3688. @kindex FORCE_COMMON_ALLOCATION
  3689. @cindex common allocation in linker script
  3690. This command has the same effect as the @samp{-d} command-line option:
  3691. to make @command{ld} assign space to common symbols even if a relocatable
  3692. output file is specified (@samp{-r}).
  3693. @item INHIBIT_COMMON_ALLOCATION
  3694. @kindex INHIBIT_COMMON_ALLOCATION
  3695. @cindex common allocation in linker script
  3696. This command has the same effect as the @samp{--no-define-common}
  3697. command-line option: to make @code{ld} omit the assignment of addresses
  3698. to common symbols even for a non-relocatable output file.
  3699. @item FORCE_GROUP_ALLOCATION
  3700. @kindex FORCE_GROUP_ALLOCATION
  3701. @cindex group allocation in linker script
  3702. @cindex section groups
  3703. @cindex COMDAT
  3704. This command has the same effect as the
  3705. @samp{--force-group-allocation} command-line option: to make
  3706. @command{ld} place section group members like normal input sections,
  3707. and to delete the section groups even if a relocatable output file is
  3708. specified (@samp{-r}).
  3709. @item INSERT [ AFTER | BEFORE ] @var{output_section}
  3710. @kindex INSERT
  3711. @cindex insert user script into default script
  3712. This command is typically used in a script specified by @samp{-T} to
  3713. augment the default @code{SECTIONS} with, for example, overlays. It
  3714. inserts all prior linker script statements after (or before)
  3715. @var{output_section}, and also causes @samp{-T} to not override the
  3716. default linker script. The exact insertion point is as for orphan
  3717. sections. @xref{Location Counter}. The insertion happens after the
  3718. linker has mapped input sections to output sections. Prior to the
  3719. insertion, since @samp{-T} scripts are parsed before the default
  3720. linker script, statements in the @samp{-T} script occur before the
  3721. default linker script statements in the internal linker representation
  3722. of the script. In particular, input section assignments will be made
  3723. to @samp{-T} output sections before those in the default script. Here
  3724. is an example of how a @samp{-T} script using @code{INSERT} might look:
  3725. @smallexample
  3726. SECTIONS
  3727. @{
  3728. OVERLAY :
  3729. @{
  3730. .ov1 @{ ov1*(.text) @}
  3731. .ov2 @{ ov2*(.text) @}
  3732. @}
  3733. @}
  3734. INSERT AFTER .text;
  3735. @end smallexample
  3736. @item NOCROSSREFS(@var{section} @var{section} @dots{})
  3737. @kindex NOCROSSREFS(@var{sections})
  3738. @cindex cross references
  3739. This command may be used to tell @command{ld} to issue an error about any
  3740. references among certain output sections.
  3741. In certain types of programs, particularly on embedded systems when
  3742. using overlays, when one section is loaded into memory, another section
  3743. will not be. Any direct references between the two sections would be
  3744. errors. For example, it would be an error if code in one section called
  3745. a function defined in the other section.
  3746. The @code{NOCROSSREFS} command takes a list of output section names. If
  3747. @command{ld} detects any cross references between the sections, it reports
  3748. an error and returns a non-zero exit status. Note that the
  3749. @code{NOCROSSREFS} command uses output section names, not input section
  3750. names.
  3751. @item NOCROSSREFS_TO(@var{tosection} @var{fromsection} @dots{})
  3752. @kindex NOCROSSREFS_TO(@var{tosection} @var{fromsections})
  3753. @cindex cross references
  3754. This command may be used to tell @command{ld} to issue an error about any
  3755. references to one section from a list of other sections.
  3756. The @code{NOCROSSREFS} command is useful when ensuring that two or more
  3757. output sections are entirely independent but there are situations where
  3758. a one-way dependency is needed. For example, in a multi-core application
  3759. there may be shared code that can be called from each core but for safety
  3760. must never call back.
  3761. The @code{NOCROSSREFS_TO} command takes a list of output section names.
  3762. The first section can not be referenced from any of the other sections.
  3763. If @command{ld} detects any references to the first section from any of
  3764. the other sections, it reports an error and returns a non-zero exit
  3765. status. Note that the @code{NOCROSSREFS_TO} command uses output section
  3766. names, not input section names.
  3767. @ifclear SingleFormat
  3768. @item OUTPUT_ARCH(@var{bfdarch})
  3769. @kindex OUTPUT_ARCH(@var{bfdarch})
  3770. @cindex machine architecture
  3771. @cindex architecture
  3772. Specify a particular output machine architecture. The argument is one
  3773. of the names used by the BFD library (@pxref{BFD}). You can see the
  3774. architecture of an object file by using the @code{objdump} program with
  3775. the @samp{-f} option.
  3776. @end ifclear
  3777. @item LD_FEATURE(@var{string})
  3778. @kindex LD_FEATURE(@var{string})
  3779. This command may be used to modify @command{ld} behavior. If
  3780. @var{string} is @code{"SANE_EXPR"} then absolute symbols and numbers
  3781. in a script are simply treated as numbers everywhere.
  3782. @xref{Expression Section}.
  3783. @end table
  3784. @node Assignments
  3785. @section Assigning Values to Symbols
  3786. @cindex assignment in scripts
  3787. @cindex symbol definition, scripts
  3788. @cindex variables, defining
  3789. You may assign a value to a symbol in a linker script. This will define
  3790. the symbol and place it into the symbol table with a global scope.
  3791. @menu
  3792. * Simple Assignments:: Simple Assignments
  3793. * HIDDEN:: HIDDEN
  3794. * PROVIDE:: PROVIDE
  3795. * PROVIDE_HIDDEN:: PROVIDE_HIDDEN
  3796. * Source Code Reference:: How to use a linker script defined symbol in source code
  3797. @end menu
  3798. @node Simple Assignments
  3799. @subsection Simple Assignments
  3800. You may assign to a symbol using any of the C assignment operators:
  3801. @table @code
  3802. @item @var{symbol} = @var{expression} ;
  3803. @itemx @var{symbol} += @var{expression} ;
  3804. @itemx @var{symbol} -= @var{expression} ;
  3805. @itemx @var{symbol} *= @var{expression} ;
  3806. @itemx @var{symbol} /= @var{expression} ;
  3807. @itemx @var{symbol} <<= @var{expression} ;
  3808. @itemx @var{symbol} >>= @var{expression} ;
  3809. @itemx @var{symbol} &= @var{expression} ;
  3810. @itemx @var{symbol} |= @var{expression} ;
  3811. @end table
  3812. The first case will define @var{symbol} to the value of
  3813. @var{expression}. In the other cases, @var{symbol} must already be
  3814. defined, and the value will be adjusted accordingly.
  3815. The special symbol name @samp{.} indicates the location counter. You
  3816. may only use this within a @code{SECTIONS} command. @xref{Location Counter}.
  3817. The semicolon after @var{expression} is required.
  3818. Expressions are defined below; see @ref{Expressions}.
  3819. You may write symbol assignments as commands in their own right, or as
  3820. statements within a @code{SECTIONS} command, or as part of an output
  3821. section description in a @code{SECTIONS} command.
  3822. The section of the symbol will be set from the section of the
  3823. expression; for more information, see @ref{Expression Section}.
  3824. Here is an example showing the three different places that symbol
  3825. assignments may be used:
  3826. @smallexample
  3827. floating_point = 0;
  3828. SECTIONS
  3829. @{
  3830. .text :
  3831. @{
  3832. *(.text)
  3833. _etext = .;
  3834. @}
  3835. _bdata = (. + 3) & ~ 3;
  3836. .data : @{ *(.data) @}
  3837. @}
  3838. @end smallexample
  3839. @noindent
  3840. In this example, the symbol @samp{floating_point} will be defined as
  3841. zero. The symbol @samp{_etext} will be defined as the address following
  3842. the last @samp{.text} input section. The symbol @samp{_bdata} will be
  3843. defined as the address following the @samp{.text} output section aligned
  3844. upward to a 4 byte boundary.
  3845. @node HIDDEN
  3846. @subsection HIDDEN
  3847. @cindex HIDDEN
  3848. For ELF targeted ports, define a symbol that will be hidden and won't be
  3849. exported. The syntax is @code{HIDDEN(@var{symbol} = @var{expression})}.
  3850. Here is the example from @ref{Simple Assignments}, rewritten to use
  3851. @code{HIDDEN}:
  3852. @smallexample
  3853. HIDDEN(floating_point = 0);
  3854. SECTIONS
  3855. @{
  3856. .text :
  3857. @{
  3858. *(.text)
  3859. HIDDEN(_etext = .);
  3860. @}
  3861. HIDDEN(_bdata = (. + 3) & ~ 3);
  3862. .data : @{ *(.data) @}
  3863. @}
  3864. @end smallexample
  3865. @noindent
  3866. In this case none of the three symbols will be visible outside this module.
  3867. @node PROVIDE
  3868. @subsection PROVIDE
  3869. @cindex PROVIDE
  3870. In some cases, it is desirable for a linker script to define a symbol
  3871. only if it is referenced and is not defined by any object included in
  3872. the link. For example, traditional linkers defined the symbol
  3873. @samp{etext}. However, ANSI C requires that the user be able to use
  3874. @samp{etext} as a function name without encountering an error. The
  3875. @code{PROVIDE} keyword may be used to define a symbol, such as
  3876. @samp{etext}, only if it is referenced but not defined. The syntax is
  3877. @code{PROVIDE(@var{symbol} = @var{expression})}.
  3878. Here is an example of using @code{PROVIDE} to define @samp{etext}:
  3879. @smallexample
  3880. SECTIONS
  3881. @{
  3882. .text :
  3883. @{
  3884. *(.text)
  3885. _etext = .;
  3886. PROVIDE(etext = .);
  3887. @}
  3888. @}
  3889. @end smallexample
  3890. In this example, if the program defines @samp{_etext} (with a leading
  3891. underscore), the linker will give a multiple definition diagnostic. If,
  3892. on the other hand, the program defines @samp{etext} (with no leading
  3893. underscore), the linker will silently use the definition in the program.
  3894. If the program references @samp{etext} but does not define it, the
  3895. linker will use the definition in the linker script.
  3896. Note - the @code{PROVIDE} directive considers a common symbol to be
  3897. defined, even though such a symbol could be combined with the symbol
  3898. that the @code{PROVIDE} would create. This is particularly important
  3899. when considering constructor and destructor list symbols such as
  3900. @samp{__CTOR_LIST__} as these are often defined as common symbols.
  3901. @node PROVIDE_HIDDEN
  3902. @subsection PROVIDE_HIDDEN
  3903. @cindex PROVIDE_HIDDEN
  3904. Similar to @code{PROVIDE}. For ELF targeted ports, the symbol will be
  3905. hidden and won't be exported.
  3906. @node Source Code Reference
  3907. @subsection Source Code Reference
  3908. Accessing a linker script defined variable from source code is not
  3909. intuitive. In particular a linker script symbol is not equivalent to
  3910. a variable declaration in a high level language, it is instead a
  3911. symbol that does not have a value.
  3912. Before going further, it is important to note that compilers often
  3913. transform names in the source code into different names when they are
  3914. stored in the symbol table. For example, Fortran compilers commonly
  3915. prepend or append an underscore, and C++ performs extensive @samp{name
  3916. mangling}. Therefore there might be a discrepancy between the name
  3917. of a variable as it is used in source code and the name of the same
  3918. variable as it is defined in a linker script. For example in C a
  3919. linker script variable might be referred to as:
  3920. @smallexample
  3921. extern int foo;
  3922. @end smallexample
  3923. But in the linker script it might be defined as:
  3924. @smallexample
  3925. _foo = 1000;
  3926. @end smallexample
  3927. In the remaining examples however it is assumed that no name
  3928. transformation has taken place.
  3929. When a symbol is declared in a high level language such as C, two
  3930. things happen. The first is that the compiler reserves enough space
  3931. in the program's memory to hold the @emph{value} of the symbol. The
  3932. second is that the compiler creates an entry in the program's symbol
  3933. table which holds the symbol's @emph{address}. ie the symbol table
  3934. contains the address of the block of memory holding the symbol's
  3935. value. So for example the following C declaration, at file scope:
  3936. @smallexample
  3937. int foo = 1000;
  3938. @end smallexample
  3939. creates an entry called @samp{foo} in the symbol table. This entry
  3940. holds the address of an @samp{int} sized block of memory where the
  3941. number 1000 is initially stored.
  3942. When a program references a symbol the compiler generates code that
  3943. first accesses the symbol table to find the address of the symbol's
  3944. memory block and then code to read the value from that memory block.
  3945. So:
  3946. @smallexample
  3947. foo = 1;
  3948. @end smallexample
  3949. looks up the symbol @samp{foo} in the symbol table, gets the address
  3950. associated with this symbol and then writes the value 1 into that
  3951. address. Whereas:
  3952. @smallexample
  3953. int * a = & foo;
  3954. @end smallexample
  3955. looks up the symbol @samp{foo} in the symbol table, gets its address
  3956. and then copies this address into the block of memory associated with
  3957. the variable @samp{a}.
  3958. Linker scripts symbol declarations, by contrast, create an entry in
  3959. the symbol table but do not assign any memory to them. Thus they are
  3960. an address without a value. So for example the linker script definition:
  3961. @smallexample
  3962. foo = 1000;
  3963. @end smallexample
  3964. creates an entry in the symbol table called @samp{foo} which holds
  3965. the address of memory location 1000, but nothing special is stored at
  3966. address 1000. This means that you cannot access the @emph{value} of a
  3967. linker script defined symbol - it has no value - all you can do is
  3968. access the @emph{address} of a linker script defined symbol.
  3969. Hence when you are using a linker script defined symbol in source code
  3970. you should always take the address of the symbol, and never attempt to
  3971. use its value. For example suppose you want to copy the contents of a
  3972. section of memory called .ROM into a section called .FLASH and the
  3973. linker script contains these declarations:
  3974. @smallexample
  3975. @group
  3976. start_of_ROM = .ROM;
  3977. end_of_ROM = .ROM + sizeof (.ROM);
  3978. start_of_FLASH = .FLASH;
  3979. @end group
  3980. @end smallexample
  3981. Then the C source code to perform the copy would be:
  3982. @smallexample
  3983. @group
  3984. extern char start_of_ROM, end_of_ROM, start_of_FLASH;
  3985. memcpy (& start_of_FLASH, & start_of_ROM, & end_of_ROM - & start_of_ROM);
  3986. @end group
  3987. @end smallexample
  3988. Note the use of the @samp{&} operators. These are correct.
  3989. Alternatively the symbols can be treated as the names of vectors or
  3990. arrays and then the code will again work as expected:
  3991. @smallexample
  3992. @group
  3993. extern char start_of_ROM[], end_of_ROM[], start_of_FLASH[];
  3994. memcpy (start_of_FLASH, start_of_ROM, end_of_ROM - start_of_ROM);
  3995. @end group
  3996. @end smallexample
  3997. Note how using this method does not require the use of @samp{&}
  3998. operators.
  3999. @node SECTIONS
  4000. @section SECTIONS Command
  4001. @kindex SECTIONS
  4002. The @code{SECTIONS} command tells the linker how to map input sections
  4003. into output sections, and how to place the output sections in memory.
  4004. The format of the @code{SECTIONS} command is:
  4005. @smallexample
  4006. SECTIONS
  4007. @{
  4008. @var{sections-command}
  4009. @var{sections-command}
  4010. @dots{}
  4011. @}
  4012. @end smallexample
  4013. Each @var{sections-command} may of be one of the following:
  4014. @itemize @bullet
  4015. @item
  4016. an @code{ENTRY} command (@pxref{Entry Point,,Entry command})
  4017. @item
  4018. a symbol assignment (@pxref{Assignments})
  4019. @item
  4020. an output section description
  4021. @item
  4022. an overlay description
  4023. @end itemize
  4024. The @code{ENTRY} command and symbol assignments are permitted inside the
  4025. @code{SECTIONS} command for convenience in using the location counter in
  4026. those commands. This can also make the linker script easier to
  4027. understand because you can use those commands at meaningful points in
  4028. the layout of the output file.
  4029. Output section descriptions and overlay descriptions are described
  4030. below.
  4031. If you do not use a @code{SECTIONS} command in your linker script, the
  4032. linker will place each input section into an identically named output
  4033. section in the order that the sections are first encountered in the
  4034. input files. If all input sections are present in the first file, for
  4035. example, the order of sections in the output file will match the order
  4036. in the first input file. The first section will be at address zero.
  4037. @menu
  4038. * Output Section Description:: Output section description
  4039. * Output Section Name:: Output section name
  4040. * Output Section Address:: Output section address
  4041. * Input Section:: Input section description
  4042. * Output Section Data:: Output section data
  4043. * Output Section Keywords:: Output section keywords
  4044. * Output Section Discarding:: Output section discarding
  4045. * Output Section Attributes:: Output section attributes
  4046. * Overlay Description:: Overlay description
  4047. @end menu
  4048. @node Output Section Description
  4049. @subsection Output Section Description
  4050. The full description of an output section looks like this:
  4051. @smallexample
  4052. @group
  4053. @var{section} [@var{address}] [(@var{type})] :
  4054. [AT(@var{lma})]
  4055. [ALIGN(@var{section_align}) | ALIGN_WITH_INPUT]
  4056. [SUBALIGN(@var{subsection_align})]
  4057. [@var{constraint}]
  4058. @{
  4059. @var{output-section-command}
  4060. @var{output-section-command}
  4061. @dots{}
  4062. @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}] [,]
  4063. @end group
  4064. @end smallexample
  4065. Most output sections do not use most of the optional section attributes.
  4066. The whitespace around @var{section} is required, so that the section
  4067. name is unambiguous. The colon and the curly braces are also required.
  4068. The comma at the end may be required if a @var{fillexp} is used and
  4069. the next @var{sections-command} looks like a continuation of the expression.
  4070. The line breaks and other white space are optional.
  4071. Each @var{output-section-command} may be one of the following:
  4072. @itemize @bullet
  4073. @item
  4074. a symbol assignment (@pxref{Assignments})
  4075. @item
  4076. an input section description (@pxref{Input Section})
  4077. @item
  4078. data values to include directly (@pxref{Output Section Data})
  4079. @item
  4080. a special output section keyword (@pxref{Output Section Keywords})
  4081. @end itemize
  4082. @node Output Section Name
  4083. @subsection Output Section Name
  4084. @cindex name, section
  4085. @cindex section name
  4086. The name of the output section is @var{section}. @var{section} must
  4087. meet the constraints of your output format. In formats which only
  4088. support a limited number of sections, such as @code{a.out}, the name
  4089. must be one of the names supported by the format (@code{a.out}, for
  4090. example, allows only @samp{.text}, @samp{.data} or @samp{.bss}). If the
  4091. output format supports any number of sections, but with numbers and not
  4092. names (as is the case for Oasys), the name should be supplied as a
  4093. quoted numeric string. A section name may consist of any sequence of
  4094. characters, but a name which contains any unusual characters such as
  4095. commas must be quoted.
  4096. The output section name @samp{/DISCARD/} is special; @ref{Output Section
  4097. Discarding}.
  4098. @node Output Section Address
  4099. @subsection Output Section Address
  4100. @cindex address, section
  4101. @cindex section address
  4102. The @var{address} is an expression for the VMA (the virtual memory
  4103. address) of the output section. This address is optional, but if it
  4104. is provided then the output address will be set exactly as specified.
  4105. If the output address is not specified then one will be chosen for the
  4106. section, based on the heuristic below. This address will be adjusted
  4107. to fit the alignment requirement of the output section. The
  4108. alignment requirement is the strictest alignment of any input section
  4109. contained within the output section.
  4110. The output section address heuristic is as follows:
  4111. @itemize @bullet
  4112. @item
  4113. If an output memory @var{region} is set for the section then it
  4114. is added to this region and its address will be the next free address
  4115. in that region.
  4116. @item
  4117. If the MEMORY command has been used to create a list of memory
  4118. regions then the first region which has attributes compatible with the
  4119. section is selected to contain it. The section's output address will
  4120. be the next free address in that region; @ref{MEMORY}.
  4121. @item
  4122. If no memory regions were specified, or none match the section then
  4123. the output address will be based on the current value of the location
  4124. counter.
  4125. @end itemize
  4126. @noindent
  4127. For example:
  4128. @smallexample
  4129. .text . : @{ *(.text) @}
  4130. @end smallexample
  4131. @noindent
  4132. and
  4133. @smallexample
  4134. .text : @{ *(.text) @}
  4135. @end smallexample
  4136. @noindent
  4137. are subtly different. The first will set the address of the
  4138. @samp{.text} output section to the current value of the location
  4139. counter. The second will set it to the current value of the location
  4140. counter aligned to the strictest alignment of any of the @samp{.text}
  4141. input sections.
  4142. The @var{address} may be an arbitrary expression; @ref{Expressions}.
  4143. For example, if you want to align the section on a 0x10 byte boundary,
  4144. so that the lowest four bits of the section address are zero, you could
  4145. do something like this:
  4146. @smallexample
  4147. .text ALIGN(0x10) : @{ *(.text) @}
  4148. @end smallexample
  4149. @noindent
  4150. This works because @code{ALIGN} returns the current location counter
  4151. aligned upward to the specified value.
  4152. Specifying @var{address} for a section will change the value of the
  4153. location counter, provided that the section is non-empty. (Empty
  4154. sections are ignored).
  4155. @node Input Section
  4156. @subsection Input Section Description
  4157. @cindex input sections
  4158. @cindex mapping input sections to output sections
  4159. The most common output section command is an input section description.
  4160. The input section description is the most basic linker script operation.
  4161. You use output sections to tell the linker how to lay out your program
  4162. in memory. You use input section descriptions to tell the linker how to
  4163. map the input files into your memory layout.
  4164. @menu
  4165. * Input Section Basics:: Input section basics
  4166. * Input Section Wildcards:: Input section wildcard patterns
  4167. * Input Section Common:: Input section for common symbols
  4168. * Input Section Keep:: Input section and garbage collection
  4169. * Input Section Example:: Input section example
  4170. @end menu
  4171. @node Input Section Basics
  4172. @subsubsection Input Section Basics
  4173. @cindex input section basics
  4174. An input section description consists of a file name optionally followed
  4175. by a list of section names in parentheses.
  4176. The file name and the section name may be wildcard patterns, which we
  4177. describe further below (@pxref{Input Section Wildcards}).
  4178. The most common input section description is to include all input
  4179. sections with a particular name in the output section. For example, to
  4180. include all input @samp{.text} sections, you would write:
  4181. @smallexample
  4182. *(.text)
  4183. @end smallexample
  4184. @noindent
  4185. Here the @samp{*} is a wildcard which matches any file name. To exclude a list
  4186. @cindex EXCLUDE_FILE
  4187. of files from matching the file name wildcard, EXCLUDE_FILE may be used to
  4188. match all files except the ones specified in the EXCLUDE_FILE list. For
  4189. example:
  4190. @smallexample
  4191. EXCLUDE_FILE (*crtend.o *otherfile.o) *(.ctors)
  4192. @end smallexample
  4193. @noindent
  4194. will cause all .ctors sections from all files except @file{crtend.o}
  4195. and @file{otherfile.o} to be included. The EXCLUDE_FILE can also be
  4196. placed inside the section list, for example:
  4197. @smallexample
  4198. *(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors)
  4199. @end smallexample
  4200. @noindent
  4201. The result of this is identically to the previous example. Supporting
  4202. two syntaxes for EXCLUDE_FILE is useful if the section list contains
  4203. more than one section, as described below.
  4204. There are two ways to include more than one section:
  4205. @smallexample
  4206. *(.text .rdata)
  4207. *(.text) *(.rdata)
  4208. @end smallexample
  4209. @noindent
  4210. The difference between these is the order in which the @samp{.text} and
  4211. @samp{.rdata} input sections will appear in the output section. In the
  4212. first example, they will be intermingled, appearing in the same order as
  4213. they are found in the linker input. In the second example, all
  4214. @samp{.text} input sections will appear first, followed by all
  4215. @samp{.rdata} input sections.
  4216. When using EXCLUDE_FILE with more than one section, if the exclusion
  4217. is within the section list then the exclusion only applies to the
  4218. immediately following section, for example:
  4219. @smallexample
  4220. *(EXCLUDE_FILE (*somefile.o) .text .rdata)
  4221. @end smallexample
  4222. @noindent
  4223. will cause all @samp{.text} sections from all files except
  4224. @file{somefile.o} to be included, while all @samp{.rdata} sections
  4225. from all files, including @file{somefile.o}, will be included. To
  4226. exclude the @samp{.rdata} sections from @file{somefile.o} the example
  4227. could be modified to:
  4228. @smallexample
  4229. *(EXCLUDE_FILE (*somefile.o) .text EXCLUDE_FILE (*somefile.o) .rdata)
  4230. @end smallexample
  4231. @noindent
  4232. Alternatively, placing the EXCLUDE_FILE outside of the section list,
  4233. before the input file selection, will cause the exclusion to apply for
  4234. all sections. Thus the previous example can be rewritten as:
  4235. @smallexample
  4236. EXCLUDE_FILE (*somefile.o) *(.text .rdata)
  4237. @end smallexample
  4238. You can specify a file name to include sections from a particular file.
  4239. You would do this if one or more of your files contain special data that
  4240. needs to be at a particular location in memory. For example:
  4241. @smallexample
  4242. data.o(.data)
  4243. @end smallexample
  4244. To refine the sections that are included based on the section flags
  4245. of an input section, INPUT_SECTION_FLAGS may be used.
  4246. Here is a simple example for using Section header flags for ELF sections:
  4247. @smallexample
  4248. @group
  4249. SECTIONS @{
  4250. .text : @{ INPUT_SECTION_FLAGS (SHF_MERGE & SHF_STRINGS) *(.text) @}
  4251. .text2 : @{ INPUT_SECTION_FLAGS (!SHF_WRITE) *(.text) @}
  4252. @}
  4253. @end group
  4254. @end smallexample
  4255. In this example, the output section @samp{.text} will be comprised of any
  4256. input section matching the name *(.text) whose section header flags
  4257. @code{SHF_MERGE} and @code{SHF_STRINGS} are set. The output section
  4258. @samp{.text2} will be comprised of any input section matching the name *(.text)
  4259. whose section header flag @code{SHF_WRITE} is clear.
  4260. You can also specify files within archives by writing a pattern
  4261. matching the archive, a colon, then the pattern matching the file,
  4262. with no whitespace around the colon.
  4263. @table @samp
  4264. @item archive:file
  4265. matches file within archive
  4266. @item archive:
  4267. matches the whole archive
  4268. @item :file
  4269. matches file but not one in an archive
  4270. @end table
  4271. Either one or both of @samp{archive} and @samp{file} can contain shell
  4272. wildcards. On DOS based file systems, the linker will assume that a
  4273. single letter followed by a colon is a drive specifier, so
  4274. @samp{c:myfile.o} is a simple file specification, not @samp{myfile.o}
  4275. within an archive called @samp{c}. @samp{archive:file} filespecs may
  4276. also be used within an @code{EXCLUDE_FILE} list, but may not appear in
  4277. other linker script contexts. For instance, you cannot extract a file
  4278. from an archive by using @samp{archive:file} in an @code{INPUT}
  4279. command.
  4280. If you use a file name without a list of sections, then all sections in
  4281. the input file will be included in the output section. This is not
  4282. commonly done, but it may by useful on occasion. For example:
  4283. @smallexample
  4284. data.o
  4285. @end smallexample
  4286. When you use a file name which is not an @samp{archive:file} specifier
  4287. and does not contain any wild card
  4288. characters, the linker will first see if you also specified the file
  4289. name on the linker command line or in an @code{INPUT} command. If you
  4290. did not, the linker will attempt to open the file as an input file, as
  4291. though it appeared on the command line. Note that this differs from an
  4292. @code{INPUT} command, because the linker will not search for the file in
  4293. the archive search path.
  4294. @node Input Section Wildcards
  4295. @subsubsection Input Section Wildcard Patterns
  4296. @cindex input section wildcards
  4297. @cindex wildcard file name patterns
  4298. @cindex file name wildcard patterns
  4299. @cindex section name wildcard patterns
  4300. In an input section description, either the file name or the section
  4301. name or both may be wildcard patterns.
  4302. The file name of @samp{*} seen in many examples is a simple wildcard
  4303. pattern for the file name.
  4304. The wildcard patterns are like those used by the Unix shell.
  4305. @table @samp
  4306. @item *
  4307. matches any number of characters
  4308. @item ?
  4309. matches any single character
  4310. @item [@var{chars}]
  4311. matches a single instance of any of the @var{chars}; the @samp{-}
  4312. character may be used to specify a range of characters, as in
  4313. @samp{[a-z]} to match any lower case letter
  4314. @item \
  4315. quotes the following character
  4316. @end table
  4317. File name wildcard patterns only match files which are explicitly
  4318. specified on the command line or in an @code{INPUT} command. The linker
  4319. does not search directories to expand wildcards.
  4320. If a file name matches more than one wildcard pattern, or if a file name
  4321. appears explicitly and is also matched by a wildcard pattern, the linker
  4322. will use the first match in the linker script. For example, this
  4323. sequence of input section descriptions is probably in error, because the
  4324. @file{data.o} rule will not be used:
  4325. @smallexample
  4326. .data : @{ *(.data) @}
  4327. .data1 : @{ data.o(.data) @}
  4328. @end smallexample
  4329. @cindex SORT_BY_NAME
  4330. Normally, the linker will place files and sections matched by wildcards
  4331. in the order in which they are seen during the link. You can change
  4332. this by using the @code{SORT_BY_NAME} keyword, which appears before a wildcard
  4333. pattern in parentheses (e.g., @code{SORT_BY_NAME(.text*)}). When the
  4334. @code{SORT_BY_NAME} keyword is used, the linker will sort the files or sections
  4335. into ascending order by name before placing them in the output file.
  4336. @cindex SORT_BY_ALIGNMENT
  4337. @code{SORT_BY_ALIGNMENT} is similar to @code{SORT_BY_NAME}.
  4338. @code{SORT_BY_ALIGNMENT} will sort sections into descending order of
  4339. alignment before placing them in the output file. Placing larger
  4340. alignments before smaller alignments can reduce the amount of padding
  4341. needed.
  4342. @cindex SORT_BY_INIT_PRIORITY
  4343. @code{SORT_BY_INIT_PRIORITY} is also similar to @code{SORT_BY_NAME}.
  4344. @code{SORT_BY_INIT_PRIORITY} will sort sections into ascending
  4345. numerical order of the GCC init_priority attribute encoded in the
  4346. section name before placing them in the output file. In
  4347. @code{.init_array.NNNNN} and @code{.fini_array.NNNNN}, @code{NNNNN} is
  4348. the init_priority. In @code{.ctors.NNNNN} and @code{.dtors.NNNNN},
  4349. @code{NNNNN} is 65535 minus the init_priority.
  4350. @cindex SORT
  4351. @code{SORT} is an alias for @code{SORT_BY_NAME}.
  4352. When there are nested section sorting commands in linker script, there
  4353. can be at most 1 level of nesting for section sorting commands.
  4354. @enumerate
  4355. @item
  4356. @code{SORT_BY_NAME} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)).
  4357. It will sort the input sections by name first, then by alignment if two
  4358. sections have the same name.
  4359. @item
  4360. @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_NAME} (wildcard section pattern)).
  4361. It will sort the input sections by alignment first, then by name if two
  4362. sections have the same alignment.
  4363. @item
  4364. @code{SORT_BY_NAME} (@code{SORT_BY_NAME} (wildcard section pattern)) is
  4365. treated the same as @code{SORT_BY_NAME} (wildcard section pattern).
  4366. @item
  4367. @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern))
  4368. is treated the same as @code{SORT_BY_ALIGNMENT} (wildcard section pattern).
  4369. @item
  4370. All other nested section sorting commands are invalid.
  4371. @end enumerate
  4372. When both command-line section sorting option and linker script
  4373. section sorting command are used, section sorting command always
  4374. takes precedence over the command-line option.
  4375. If the section sorting command in linker script isn't nested, the
  4376. command-line option will make the section sorting command to be
  4377. treated as nested sorting command.
  4378. @enumerate
  4379. @item
  4380. @code{SORT_BY_NAME} (wildcard section pattern ) with
  4381. @option{--sort-sections alignment} is equivalent to
  4382. @code{SORT_BY_NAME} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)).
  4383. @item
  4384. @code{SORT_BY_ALIGNMENT} (wildcard section pattern) with
  4385. @option{--sort-section name} is equivalent to
  4386. @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_NAME} (wildcard section pattern)).
  4387. @end enumerate
  4388. If the section sorting command in linker script is nested, the
  4389. command-line option will be ignored.
  4390. @cindex SORT_NONE
  4391. @code{SORT_NONE} disables section sorting by ignoring the command-line
  4392. section sorting option.
  4393. If you ever get confused about where input sections are going, use the
  4394. @samp{-M} linker option to generate a map file. The map file shows
  4395. precisely how input sections are mapped to output sections.
  4396. This example shows how wildcard patterns might be used to partition
  4397. files. This linker script directs the linker to place all @samp{.text}
  4398. sections in @samp{.text} and all @samp{.bss} sections in @samp{.bss}.
  4399. The linker will place the @samp{.data} section from all files beginning
  4400. with an upper case character in @samp{.DATA}; for all other files, the
  4401. linker will place the @samp{.data} section in @samp{.data}.
  4402. @smallexample
  4403. @group
  4404. SECTIONS @{
  4405. .text : @{ *(.text) @}
  4406. .DATA : @{ [A-Z]*(.data) @}
  4407. .data : @{ *(.data) @}
  4408. .bss : @{ *(.bss) @}
  4409. @}
  4410. @end group
  4411. @end smallexample
  4412. @node Input Section Common
  4413. @subsubsection Input Section for Common Symbols
  4414. @cindex common symbol placement
  4415. @cindex uninitialized data placement
  4416. A special notation is needed for common symbols, because in many object
  4417. file formats common symbols do not have a particular input section. The
  4418. linker treats common symbols as though they are in an input section
  4419. named @samp{COMMON}.
  4420. You may use file names with the @samp{COMMON} section just as with any
  4421. other input sections. You can use this to place common symbols from a
  4422. particular input file in one section while common symbols from other
  4423. input files are placed in another section.
  4424. In most cases, common symbols in input files will be placed in the
  4425. @samp{.bss} section in the output file. For example:
  4426. @smallexample
  4427. .bss @{ *(.bss) *(COMMON) @}
  4428. @end smallexample
  4429. @cindex scommon section
  4430. @cindex small common symbols
  4431. Some object file formats have more than one type of common symbol. For
  4432. example, the MIPS ELF object file format distinguishes standard common
  4433. symbols and small common symbols. In this case, the linker will use a
  4434. different special section name for other types of common symbols. In
  4435. the case of MIPS ELF, the linker uses @samp{COMMON} for standard common
  4436. symbols and @samp{.scommon} for small common symbols. This permits you
  4437. to map the different types of common symbols into memory at different
  4438. locations.
  4439. @cindex [COMMON]
  4440. You will sometimes see @samp{[COMMON]} in old linker scripts. This
  4441. notation is now considered obsolete. It is equivalent to
  4442. @samp{*(COMMON)}.
  4443. @node Input Section Keep
  4444. @subsubsection Input Section and Garbage Collection
  4445. @cindex KEEP
  4446. @cindex garbage collection
  4447. When link-time garbage collection is in use (@samp{--gc-sections}),
  4448. it is often useful to mark sections that should not be eliminated.
  4449. This is accomplished by surrounding an input section's wildcard entry
  4450. with @code{KEEP()}, as in @code{KEEP(*(.init))} or
  4451. @code{KEEP(SORT_BY_NAME(*)(.ctors))}.
  4452. @node Input Section Example
  4453. @subsubsection Input Section Example
  4454. The following example is a complete linker script. It tells the linker
  4455. to read all of the sections from file @file{all.o} and place them at the
  4456. start of output section @samp{outputa} which starts at location
  4457. @samp{0x10000}. All of section @samp{.input1} from file @file{foo.o}
  4458. follows immediately, in the same output section. All of section
  4459. @samp{.input2} from @file{foo.o} goes into output section
  4460. @samp{outputb}, followed by section @samp{.input1} from @file{foo1.o}.
  4461. All of the remaining @samp{.input1} and @samp{.input2} sections from any
  4462. files are written to output section @samp{outputc}.
  4463. @smallexample
  4464. @group
  4465. SECTIONS @{
  4466. outputa 0x10000 :
  4467. @{
  4468. all.o
  4469. foo.o (.input1)
  4470. @}
  4471. @end group
  4472. @group
  4473. outputb :
  4474. @{
  4475. foo.o (.input2)
  4476. foo1.o (.input1)
  4477. @}
  4478. @end group
  4479. @group
  4480. outputc :
  4481. @{
  4482. *(.input1)
  4483. *(.input2)
  4484. @}
  4485. @}
  4486. @end group
  4487. @end smallexample
  4488. If an output section's name is the same as the input section's name
  4489. and is representable as a C identifier, then the linker will
  4490. automatically @pxref{PROVIDE} two symbols: __start_SECNAME and
  4491. __stop_SECNAME, where SECNAME is the name of the section. These
  4492. indicate the start address and end address of the output section
  4493. respectively. Note: most section names are not representable as
  4494. C identifiers because they contain a @samp{.} character.
  4495. @node Output Section Data
  4496. @subsection Output Section Data
  4497. @cindex data
  4498. @cindex section data
  4499. @cindex output section data
  4500. @kindex BYTE(@var{expression})
  4501. @kindex SHORT(@var{expression})
  4502. @kindex LONG(@var{expression})
  4503. @kindex QUAD(@var{expression})
  4504. @kindex SQUAD(@var{expression})
  4505. You can include explicit bytes of data in an output section by using
  4506. @code{BYTE}, @code{SHORT}, @code{LONG}, @code{QUAD}, or @code{SQUAD} as
  4507. an output section command. Each keyword is followed by an expression in
  4508. parentheses providing the value to store (@pxref{Expressions}). The
  4509. value of the expression is stored at the current value of the location
  4510. counter.
  4511. The @code{BYTE}, @code{SHORT}, @code{LONG}, and @code{QUAD} commands
  4512. store one, two, four, and eight bytes (respectively). After storing the
  4513. bytes, the location counter is incremented by the number of bytes
  4514. stored.
  4515. For example, this will store the byte 1 followed by the four byte value
  4516. of the symbol @samp{addr}:
  4517. @smallexample
  4518. BYTE(1)
  4519. LONG(addr)
  4520. @end smallexample
  4521. When using a 64 bit host or target, @code{QUAD} and @code{SQUAD} are the
  4522. same; they both store an 8 byte, or 64 bit, value. When both host and
  4523. target are 32 bits, an expression is computed as 32 bits. In this case
  4524. @code{QUAD} stores a 32 bit value zero extended to 64 bits, and
  4525. @code{SQUAD} stores a 32 bit value sign extended to 64 bits.
  4526. If the object file format of the output file has an explicit endianness,
  4527. which is the normal case, the value will be stored in that endianness.
  4528. When the object file format does not have an explicit endianness, as is
  4529. true of, for example, S-records, the value will be stored in the
  4530. endianness of the first input object file.
  4531. Note---these commands only work inside a section description and not
  4532. between them, so the following will produce an error from the linker:
  4533. @smallexample
  4534. SECTIONS @{@ .text : @{@ *(.text) @}@ LONG(1) .data : @{@ *(.data) @}@ @}@
  4535. @end smallexample
  4536. whereas this will work:
  4537. @smallexample
  4538. SECTIONS @{@ .text : @{@ *(.text) ; LONG(1) @}@ .data : @{@ *(.data) @}@ @}@
  4539. @end smallexample
  4540. @kindex FILL(@var{expression})
  4541. @cindex holes, filling
  4542. @cindex unspecified memory
  4543. You may use the @code{FILL} command to set the fill pattern for the
  4544. current section. It is followed by an expression in parentheses. Any
  4545. otherwise unspecified regions of memory within the section (for example,
  4546. gaps left due to the required alignment of input sections) are filled
  4547. with the value of the expression, repeated as
  4548. necessary. A @code{FILL} statement covers memory locations after the
  4549. point at which it occurs in the section definition; by including more
  4550. than one @code{FILL} statement, you can have different fill patterns in
  4551. different parts of an output section.
  4552. This example shows how to fill unspecified regions of memory with the
  4553. value @samp{0x90}:
  4554. @smallexample
  4555. FILL(0x90909090)
  4556. @end smallexample
  4557. The @code{FILL} command is similar to the @samp{=@var{fillexp}} output
  4558. section attribute, but it only affects the
  4559. part of the section following the @code{FILL} command, rather than the
  4560. entire section. If both are used, the @code{FILL} command takes
  4561. precedence. @xref{Output Section Fill}, for details on the fill
  4562. expression.
  4563. @node Output Section Keywords
  4564. @subsection Output Section Keywords
  4565. There are a couple of keywords which can appear as output section
  4566. commands.
  4567. @table @code
  4568. @kindex CREATE_OBJECT_SYMBOLS
  4569. @cindex input filename symbols
  4570. @cindex filename symbols
  4571. @item CREATE_OBJECT_SYMBOLS
  4572. The command tells the linker to create a symbol for each input file.
  4573. The name of each symbol will be the name of the corresponding input
  4574. file. The section of each symbol will be the output section in which
  4575. the @code{CREATE_OBJECT_SYMBOLS} command appears.
  4576. This is conventional for the a.out object file format. It is not
  4577. normally used for any other object file format.
  4578. @kindex CONSTRUCTORS
  4579. @cindex C++ constructors, arranging in link
  4580. @cindex constructors, arranging in link
  4581. @item CONSTRUCTORS
  4582. When linking using the a.out object file format, the linker uses an
  4583. unusual set construct to support C++ global constructors and
  4584. destructors. When linking object file formats which do not support
  4585. arbitrary sections, such as ECOFF and XCOFF, the linker will
  4586. automatically recognize C++ global constructors and destructors by name.
  4587. For these object file formats, the @code{CONSTRUCTORS} command tells the
  4588. linker to place constructor information in the output section where the
  4589. @code{CONSTRUCTORS} command appears. The @code{CONSTRUCTORS} command is
  4590. ignored for other object file formats.
  4591. The symbol @w{@code{__CTOR_LIST__}} marks the start of the global
  4592. constructors, and the symbol @w{@code{__CTOR_END__}} marks the end.
  4593. Similarly, @w{@code{__DTOR_LIST__}} and @w{@code{__DTOR_END__}} mark
  4594. the start and end of the global destructors. The
  4595. first word in the list is the number of entries, followed by the address
  4596. of each constructor or destructor, followed by a zero word. The
  4597. compiler must arrange to actually run the code. For these object file
  4598. formats @sc{gnu} C++ normally calls constructors from a subroutine
  4599. @code{__main}; a call to @code{__main} is automatically inserted into
  4600. the startup code for @code{main}. @sc{gnu} C++ normally runs
  4601. destructors either by using @code{atexit}, or directly from the function
  4602. @code{exit}.
  4603. For object file formats such as @code{COFF} or @code{ELF} which support
  4604. arbitrary section names, @sc{gnu} C++ will normally arrange to put the
  4605. addresses of global constructors and destructors into the @code{.ctors}
  4606. and @code{.dtors} sections. Placing the following sequence into your
  4607. linker script will build the sort of table which the @sc{gnu} C++
  4608. runtime code expects to see.
  4609. @smallexample
  4610. __CTOR_LIST__ = .;
  4611. LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
  4612. *(.ctors)
  4613. LONG(0)
  4614. __CTOR_END__ = .;
  4615. __DTOR_LIST__ = .;
  4616. LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
  4617. *(.dtors)
  4618. LONG(0)
  4619. __DTOR_END__ = .;
  4620. @end smallexample
  4621. If you are using the @sc{gnu} C++ support for initialization priority,
  4622. which provides some control over the order in which global constructors
  4623. are run, you must sort the constructors at link time to ensure that they
  4624. are executed in the correct order. When using the @code{CONSTRUCTORS}
  4625. command, use @samp{SORT_BY_NAME(CONSTRUCTORS)} instead. When using the
  4626. @code{.ctors} and @code{.dtors} sections, use @samp{*(SORT_BY_NAME(.ctors))} and
  4627. @samp{*(SORT_BY_NAME(.dtors))} instead of just @samp{*(.ctors)} and
  4628. @samp{*(.dtors)}.
  4629. Normally the compiler and linker will handle these issues automatically,
  4630. and you will not need to concern yourself with them. However, you may
  4631. need to consider this if you are using C++ and writing your own linker
  4632. scripts.
  4633. @end table
  4634. @node Output Section Discarding
  4635. @subsection Output Section Discarding
  4636. @cindex discarding sections
  4637. @cindex sections, discarding
  4638. @cindex removing sections
  4639. The linker will not normally create output sections with no contents.
  4640. This is for convenience when referring to input sections that may or
  4641. may not be present in any of the input files. For example:
  4642. @smallexample
  4643. .foo : @{ *(.foo) @}
  4644. @end smallexample
  4645. @noindent
  4646. will only create a @samp{.foo} section in the output file if there is a
  4647. @samp{.foo} section in at least one input file, and if the input
  4648. sections are not all empty. Other link script directives that allocate
  4649. space in an output section will also create the output section. So
  4650. too will assignments to dot even if the assignment does not create
  4651. space, except for @samp{. = 0}, @samp{. = . + 0}, @samp{. = sym},
  4652. @samp{. = . + sym} and @samp{. = ALIGN (. != 0, expr, 1)} when
  4653. @samp{sym} is an absolute symbol of value 0 defined in the script.
  4654. This allows you to force output of an empty section with @samp{. = .}.
  4655. The linker will ignore address assignments (@pxref{Output Section Address})
  4656. on discarded output sections, except when the linker script defines
  4657. symbols in the output section. In that case the linker will obey
  4658. the address assignments, possibly advancing dot even though the
  4659. section is discarded.
  4660. @cindex /DISCARD/
  4661. The special output section name @samp{/DISCARD/} may be used to discard
  4662. input sections. Any input sections which are assigned to an output
  4663. section named @samp{/DISCARD/} are not included in the output file.
  4664. This can be used to discard input sections marked with the ELF flag
  4665. @code{SHF_GNU_RETAIN}, which would otherwise have been saved from linker
  4666. garbage collection.
  4667. Note, sections that match the @samp{/DISCARD/} output section will be
  4668. discarded even if they are in an ELF section group which has other
  4669. members which are not being discarded. This is deliberate.
  4670. Discarding takes precedence over grouping.
  4671. @node Output Section Attributes
  4672. @subsection Output Section Attributes
  4673. @cindex output section attributes
  4674. We showed above that the full description of an output section looked
  4675. like this:
  4676. @smallexample
  4677. @group
  4678. @var{section} [@var{address}] [(@var{type})] :
  4679. [AT(@var{lma})]
  4680. [ALIGN(@var{section_align}) | ALIGN_WITH_INPUT]
  4681. [SUBALIGN(@var{subsection_align})]
  4682. [@var{constraint}]
  4683. @{
  4684. @var{output-section-command}
  4685. @var{output-section-command}
  4686. @dots{}
  4687. @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}]
  4688. @end group
  4689. @end smallexample
  4690. We've already described @var{section}, @var{address}, and
  4691. @var{output-section-command}. In this section we will describe the
  4692. remaining section attributes.
  4693. @menu
  4694. * Output Section Type:: Output section type
  4695. * Output Section LMA:: Output section LMA
  4696. * Forced Output Alignment:: Forced Output Alignment
  4697. * Forced Input Alignment:: Forced Input Alignment
  4698. * Output Section Constraint:: Output section constraint
  4699. * Output Section Region:: Output section region
  4700. * Output Section Phdr:: Output section phdr
  4701. * Output Section Fill:: Output section fill
  4702. @end menu
  4703. @node Output Section Type
  4704. @subsubsection Output Section Type
  4705. Each output section may have a type. The type is a keyword in
  4706. parentheses. The following types are defined:
  4707. @table @code
  4708. @item NOLOAD
  4709. The section should be marked as not loadable, so that it will not be
  4710. loaded into memory when the program is run.
  4711. @item READONLY
  4712. The section should be marked as read-only.
  4713. @item DSECT
  4714. @item COPY
  4715. @item INFO
  4716. @item OVERLAY
  4717. These type names are supported for backward compatibility, and are
  4718. rarely used. They all have the same effect: the section should be
  4719. marked as not allocatable, so that no memory is allocated for the
  4720. section when the program is run.
  4721. @item TYPE = @var{type}
  4722. Set the section type to the integer @var{type}. When generating an ELF
  4723. output file, type names @code{SHT_PROGBITS}, @code{SHT_STRTAB},
  4724. @code{SHT_NOTE}, @code{SHT_NOBITS}, @code{SHT_INIT_ARRAY},
  4725. @code{SHT_FINI_ARRAY}, and @code{SHT_PREINIT_ARRAY} are also allowed
  4726. for @var{type}. It is the user's responsibility to ensure that any
  4727. special requirements of the section type are met.
  4728. @item READONLY ( TYPE = @var{type} )
  4729. This form of the syntax combines the @var{READONLY} type with the
  4730. type specified by @var{type}.
  4731. @end table
  4732. @kindex NOLOAD
  4733. @cindex prevent unnecessary loading
  4734. @cindex loading, preventing
  4735. The linker normally sets the attributes of an output section based on
  4736. the input sections which map into it. You can override this by using
  4737. the section type. For example, in the script sample below, the
  4738. @samp{ROM} section is addressed at memory location @samp{0} and does not
  4739. need to be loaded when the program is run.
  4740. @smallexample
  4741. @group
  4742. SECTIONS @{
  4743. ROM 0 (NOLOAD) : @{ @dots{} @}
  4744. @dots{}
  4745. @}
  4746. @end group
  4747. @end smallexample
  4748. @node Output Section LMA
  4749. @subsubsection Output Section LMA
  4750. @kindex AT>@var{lma_region}
  4751. @kindex AT(@var{lma})
  4752. @cindex load address
  4753. @cindex section load address
  4754. Every section has a virtual address (VMA) and a load address (LMA); see
  4755. @ref{Basic Script Concepts}. The virtual address is specified by the
  4756. @pxref{Output Section Address} described earlier. The load address is
  4757. specified by the @code{AT} or @code{AT>} keywords. Specifying a load
  4758. address is optional.
  4759. The @code{AT} keyword takes an expression as an argument. This
  4760. specifies the exact load address of the section. The @code{AT>} keyword
  4761. takes the name of a memory region as an argument. @xref{MEMORY}. The
  4762. load address of the section is set to the next free address in the
  4763. region, aligned to the section's alignment requirements.
  4764. If neither @code{AT} nor @code{AT>} is specified for an allocatable
  4765. section, the linker will use the following heuristic to determine the
  4766. load address:
  4767. @itemize @bullet
  4768. @item
  4769. If the section has a specific VMA address, then this is used as
  4770. the LMA address as well.
  4771. @item
  4772. If the section is not allocatable then its LMA is set to its VMA.
  4773. @item
  4774. Otherwise if a memory region can be found that is compatible
  4775. with the current section, and this region contains at least one
  4776. section, then the LMA is set so the difference between the
  4777. VMA and LMA is the same as the difference between the VMA and LMA of
  4778. the last section in the located region.
  4779. @item
  4780. If no memory regions have been declared then a default region
  4781. that covers the entire address space is used in the previous step.
  4782. @item
  4783. If no suitable region could be found, or there was no previous
  4784. section then the LMA is set equal to the VMA.
  4785. @end itemize
  4786. @cindex ROM initialized data
  4787. @cindex initialized data in ROM
  4788. This feature is designed to make it easy to build a ROM image. For
  4789. example, the following linker script creates three output sections: one
  4790. called @samp{.text}, which starts at @code{0x1000}, one called
  4791. @samp{.mdata}, which is loaded at the end of the @samp{.text} section
  4792. even though its VMA is @code{0x2000}, and one called @samp{.bss} to hold
  4793. uninitialized data at address @code{0x3000}. The symbol @code{_data} is
  4794. defined with the value @code{0x2000}, which shows that the location
  4795. counter holds the VMA value, not the LMA value.
  4796. @smallexample
  4797. @group
  4798. SECTIONS
  4799. @{
  4800. .text 0x1000 : @{ *(.text) _etext = . ; @}
  4801. .mdata 0x2000 :
  4802. AT ( ADDR (.text) + SIZEOF (.text) )
  4803. @{ _data = . ; *(.data); _edata = . ; @}
  4804. .bss 0x3000 :
  4805. @{ _bstart = . ; *(.bss) *(COMMON) ; _bend = . ;@}
  4806. @}
  4807. @end group
  4808. @end smallexample
  4809. The run-time initialization code for use with a program generated with
  4810. this linker script would include something like the following, to copy
  4811. the initialized data from the ROM image to its runtime address. Notice
  4812. how this code takes advantage of the symbols defined by the linker
  4813. script.
  4814. @smallexample
  4815. @group
  4816. extern char _etext, _data, _edata, _bstart, _bend;
  4817. char *src = &_etext;
  4818. char *dst = &_data;
  4819. /* ROM has data at end of text; copy it. */
  4820. while (dst < &_edata)
  4821. *dst++ = *src++;
  4822. /* Zero bss. */
  4823. for (dst = &_bstart; dst< &_bend; dst++)
  4824. *dst = 0;
  4825. @end group
  4826. @end smallexample
  4827. @node Forced Output Alignment
  4828. @subsubsection Forced Output Alignment
  4829. @kindex ALIGN(@var{section_align})
  4830. @cindex forcing output section alignment
  4831. @cindex output section alignment
  4832. You can increase an output section's alignment by using ALIGN. As an
  4833. alternative you can enforce that the difference between the VMA and LMA remains
  4834. intact throughout this output section with the ALIGN_WITH_INPUT attribute.
  4835. @node Forced Input Alignment
  4836. @subsubsection Forced Input Alignment
  4837. @kindex SUBALIGN(@var{subsection_align})
  4838. @cindex forcing input section alignment
  4839. @cindex input section alignment
  4840. You can force input section alignment within an output section by using
  4841. SUBALIGN. The value specified overrides any alignment given by input
  4842. sections, whether larger or smaller.
  4843. @node Output Section Constraint
  4844. @subsubsection Output Section Constraint
  4845. @kindex ONLY_IF_RO
  4846. @kindex ONLY_IF_RW
  4847. @cindex constraints on output sections
  4848. You can specify that an output section should only be created if all
  4849. of its input sections are read-only or all of its input sections are
  4850. read-write by using the keyword @code{ONLY_IF_RO} and
  4851. @code{ONLY_IF_RW} respectively.
  4852. @node Output Section Region
  4853. @subsubsection Output Section Region
  4854. @kindex >@var{region}
  4855. @cindex section, assigning to memory region
  4856. @cindex memory regions and sections
  4857. You can assign a section to a previously defined region of memory by
  4858. using @samp{>@var{region}}. @xref{MEMORY}.
  4859. Here is a simple example:
  4860. @smallexample
  4861. @group
  4862. MEMORY @{ rom : ORIGIN = 0x1000, LENGTH = 0x1000 @}
  4863. SECTIONS @{ ROM : @{ *(.text) @} >rom @}
  4864. @end group
  4865. @end smallexample
  4866. @node Output Section Phdr
  4867. @subsubsection Output Section Phdr
  4868. @kindex :@var{phdr}
  4869. @cindex section, assigning to program header
  4870. @cindex program headers and sections
  4871. You can assign a section to a previously defined program segment by
  4872. using @samp{:@var{phdr}}. @xref{PHDRS}. If a section is assigned to
  4873. one or more segments, then all subsequent allocated sections will be
  4874. assigned to those segments as well, unless they use an explicitly
  4875. @code{:@var{phdr}} modifier. You can use @code{:NONE} to tell the
  4876. linker to not put the section in any segment at all.
  4877. Here is a simple example:
  4878. @smallexample
  4879. @group
  4880. PHDRS @{ text PT_LOAD ; @}
  4881. SECTIONS @{ .text : @{ *(.text) @} :text @}
  4882. @end group
  4883. @end smallexample
  4884. @node Output Section Fill
  4885. @subsubsection Output Section Fill
  4886. @kindex =@var{fillexp}
  4887. @cindex section fill pattern
  4888. @cindex fill pattern, entire section
  4889. You can set the fill pattern for an entire section by using
  4890. @samp{=@var{fillexp}}. @var{fillexp} is an expression
  4891. (@pxref{Expressions}). Any otherwise unspecified regions of memory
  4892. within the output section (for example, gaps left due to the required
  4893. alignment of input sections) will be filled with the value, repeated as
  4894. necessary. If the fill expression is a simple hex number, ie. a string
  4895. of hex digit starting with @samp{0x} and without a trailing @samp{k} or @samp{M}, then
  4896. an arbitrarily long sequence of hex digits can be used to specify the
  4897. fill pattern; Leading zeros become part of the pattern too. For all
  4898. other cases, including extra parentheses or a unary @code{+}, the fill
  4899. pattern is the four least significant bytes of the value of the
  4900. expression. In all cases, the number is big-endian.
  4901. You can also change the fill value with a @code{FILL} command in the
  4902. output section commands; (@pxref{Output Section Data}).
  4903. Here is a simple example:
  4904. @smallexample
  4905. @group
  4906. SECTIONS @{ .text : @{ *(.text) @} =0x90909090 @}
  4907. @end group
  4908. @end smallexample
  4909. @node Overlay Description
  4910. @subsection Overlay Description
  4911. @kindex OVERLAY
  4912. @cindex overlays
  4913. An overlay description provides an easy way to describe sections which
  4914. are to be loaded as part of a single memory image but are to be run at
  4915. the same memory address. At run time, some sort of overlay manager will
  4916. copy the overlaid sections in and out of the runtime memory address as
  4917. required, perhaps by simply manipulating addressing bits. This approach
  4918. can be useful, for example, when a certain region of memory is faster
  4919. than another.
  4920. Overlays are described using the @code{OVERLAY} command. The
  4921. @code{OVERLAY} command is used within a @code{SECTIONS} command, like an
  4922. output section description. The full syntax of the @code{OVERLAY}
  4923. command is as follows:
  4924. @smallexample
  4925. @group
  4926. OVERLAY [@var{start}] : [NOCROSSREFS] [AT ( @var{ldaddr} )]
  4927. @{
  4928. @var{secname1}
  4929. @{
  4930. @var{output-section-command}
  4931. @var{output-section-command}
  4932. @dots{}
  4933. @} [:@var{phdr}@dots{}] [=@var{fill}]
  4934. @var{secname2}
  4935. @{
  4936. @var{output-section-command}
  4937. @var{output-section-command}
  4938. @dots{}
  4939. @} [:@var{phdr}@dots{}] [=@var{fill}]
  4940. @dots{}
  4941. @} [>@var{region}] [:@var{phdr}@dots{}] [=@var{fill}] [,]
  4942. @end group
  4943. @end smallexample
  4944. Everything is optional except @code{OVERLAY} (a keyword), and each
  4945. section must have a name (@var{secname1} and @var{secname2} above). The
  4946. section definitions within the @code{OVERLAY} construct are identical to
  4947. those within the general @code{SECTIONS} construct (@pxref{SECTIONS}),
  4948. except that no addresses and no memory regions may be defined for
  4949. sections within an @code{OVERLAY}.
  4950. The comma at the end may be required if a @var{fill} is used and
  4951. the next @var{sections-command} looks like a continuation of the expression.
  4952. The sections are all defined with the same starting address. The load
  4953. addresses of the sections are arranged such that they are consecutive in
  4954. memory starting at the load address used for the @code{OVERLAY} as a
  4955. whole (as with normal section definitions, the load address is optional,
  4956. and defaults to the start address; the start address is also optional,
  4957. and defaults to the current value of the location counter).
  4958. If the @code{NOCROSSREFS} keyword is used, and there are any
  4959. references among the sections, the linker will report an error. Since
  4960. the sections all run at the same address, it normally does not make
  4961. sense for one section to refer directly to another.
  4962. @xref{Miscellaneous Commands, NOCROSSREFS}.
  4963. For each section within the @code{OVERLAY}, the linker automatically
  4964. provides two symbols. The symbol @code{__load_start_@var{secname}} is
  4965. defined as the starting load address of the section. The symbol
  4966. @code{__load_stop_@var{secname}} is defined as the final load address of
  4967. the section. Any characters within @var{secname} which are not legal
  4968. within C identifiers are removed. C (or assembler) code may use these
  4969. symbols to move the overlaid sections around as necessary.
  4970. At the end of the overlay, the value of the location counter is set to
  4971. the start address of the overlay plus the size of the largest section.
  4972. Here is an example. Remember that this would appear inside a
  4973. @code{SECTIONS} construct.
  4974. @smallexample
  4975. @group
  4976. OVERLAY 0x1000 : AT (0x4000)
  4977. @{
  4978. .text0 @{ o1/*.o(.text) @}
  4979. .text1 @{ o2/*.o(.text) @}
  4980. @}
  4981. @end group
  4982. @end smallexample
  4983. @noindent
  4984. This will define both @samp{.text0} and @samp{.text1} to start at
  4985. address 0x1000. @samp{.text0} will be loaded at address 0x4000, and
  4986. @samp{.text1} will be loaded immediately after @samp{.text0}. The
  4987. following symbols will be defined if referenced: @code{__load_start_text0},
  4988. @code{__load_stop_text0}, @code{__load_start_text1},
  4989. @code{__load_stop_text1}.
  4990. C code to copy overlay @code{.text1} into the overlay area might look
  4991. like the following.
  4992. @smallexample
  4993. @group
  4994. extern char __load_start_text1, __load_stop_text1;
  4995. memcpy ((char *) 0x1000, &__load_start_text1,
  4996. &__load_stop_text1 - &__load_start_text1);
  4997. @end group
  4998. @end smallexample
  4999. Note that the @code{OVERLAY} command is just syntactic sugar, since
  5000. everything it does can be done using the more basic commands. The above
  5001. example could have been written identically as follows.
  5002. @smallexample
  5003. @group
  5004. .text0 0x1000 : AT (0x4000) @{ o1/*.o(.text) @}
  5005. PROVIDE (__load_start_text0 = LOADADDR (.text0));
  5006. PROVIDE (__load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0));
  5007. .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) @{ o2/*.o(.text) @}
  5008. PROVIDE (__load_start_text1 = LOADADDR (.text1));
  5009. PROVIDE (__load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1));
  5010. . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1));
  5011. @end group
  5012. @end smallexample
  5013. @node MEMORY
  5014. @section MEMORY Command
  5015. @kindex MEMORY
  5016. @cindex memory regions
  5017. @cindex regions of memory
  5018. @cindex allocating memory
  5019. @cindex discontinuous memory
  5020. The linker's default configuration permits allocation of all available
  5021. memory. You can override this by using the @code{MEMORY} command.
  5022. The @code{MEMORY} command describes the location and size of blocks of
  5023. memory in the target. You can use it to describe which memory regions
  5024. may be used by the linker, and which memory regions it must avoid. You
  5025. can then assign sections to particular memory regions. The linker will
  5026. set section addresses based on the memory regions, and will warn about
  5027. regions that become too full. The linker will not shuffle sections
  5028. around to fit into the available regions.
  5029. A linker script may contain many uses of the @code{MEMORY} command,
  5030. however, all memory blocks defined are treated as if they were
  5031. specified inside a single @code{MEMORY} command. The syntax for
  5032. @code{MEMORY} is:
  5033. @smallexample
  5034. @group
  5035. MEMORY
  5036. @{
  5037. @var{name} [(@var{attr})] : ORIGIN = @var{origin}, LENGTH = @var{len}
  5038. @dots{}
  5039. @}
  5040. @end group
  5041. @end smallexample
  5042. The @var{name} is a name used in the linker script to refer to the
  5043. region. The region name has no meaning outside of the linker script.
  5044. Region names are stored in a separate name space, and will not conflict
  5045. with symbol names, file names, or section names. Each memory region
  5046. must have a distinct name within the @code{MEMORY} command. However you can
  5047. add later alias names to existing memory regions with the @ref{REGION_ALIAS}
  5048. command.
  5049. @cindex memory region attributes
  5050. The @var{attr} string is an optional list of attributes that specify
  5051. whether to use a particular memory region for an input section which is
  5052. not explicitly mapped in the linker script. As described in
  5053. @ref{SECTIONS}, if you do not specify an output section for some input
  5054. section, the linker will create an output section with the same name as
  5055. the input section. If you define region attributes, the linker will use
  5056. them to select the memory region for the output section that it creates.
  5057. The @var{attr} string must consist only of the following characters:
  5058. @table @samp
  5059. @item R
  5060. Read-only section
  5061. @item W
  5062. Read/write section
  5063. @item X
  5064. Executable section
  5065. @item A
  5066. Allocatable section
  5067. @item I
  5068. Initialized section
  5069. @item L
  5070. Same as @samp{I}
  5071. @item !
  5072. Invert the sense of any of the attributes that follow
  5073. @end table
  5074. If an unmapped section matches any of the listed attributes other than
  5075. @samp{!}, it will be placed in the memory region. The @samp{!}
  5076. attribute reverses the test for the characters that follow, so that an
  5077. unmapped section will be placed in the memory region only if it does
  5078. not match any of the attributes listed afterwards. Thus an attribute
  5079. string of @samp{RW!X} will match any unmapped section that has either
  5080. or both of the @samp{R} and @samp{W} attributes, but only as long as
  5081. the section does not also have the @samp{X} attribute.
  5082. @kindex ORIGIN =
  5083. @kindex o =
  5084. @kindex org =
  5085. The @var{origin} is an numerical expression for the start address of
  5086. the memory region. The expression must evaluate to a constant and it
  5087. cannot involve any symbols. The keyword @code{ORIGIN} may be
  5088. abbreviated to @code{org} or @code{o} (but not, for example,
  5089. @code{ORG}).
  5090. @kindex LENGTH =
  5091. @kindex len =
  5092. @kindex l =
  5093. The @var{len} is an expression for the size in bytes of the memory
  5094. region. As with the @var{origin} expression, the expression must
  5095. be numerical only and must evaluate to a constant. The keyword
  5096. @code{LENGTH} may be abbreviated to @code{len} or @code{l}.
  5097. In the following example, we specify that there are two memory regions
  5098. available for allocation: one starting at @samp{0} for 256 kilobytes,
  5099. and the other starting at @samp{0x40000000} for four megabytes. The
  5100. linker will place into the @samp{rom} memory region every section which
  5101. is not explicitly mapped into a memory region, and is either read-only
  5102. or executable. The linker will place other sections which are not
  5103. explicitly mapped into a memory region into the @samp{ram} memory
  5104. region.
  5105. @smallexample
  5106. @group
  5107. MEMORY
  5108. @{
  5109. rom (rx) : ORIGIN = 0, LENGTH = 256K
  5110. ram (!rx) : org = 0x40000000, l = 4M
  5111. @}
  5112. @end group
  5113. @end smallexample
  5114. Once you define a memory region, you can direct the linker to place
  5115. specific output sections into that memory region by using the
  5116. @samp{>@var{region}} output section attribute. For example, if you have
  5117. a memory region named @samp{mem}, you would use @samp{>mem} in the
  5118. output section definition. @xref{Output Section Region}. If no address
  5119. was specified for the output section, the linker will set the address to
  5120. the next available address within the memory region. If the combined
  5121. output sections directed to a memory region are too large for the
  5122. region, the linker will issue an error message.
  5123. It is possible to access the origin and length of a memory in an
  5124. expression via the @code{ORIGIN(@var{memory})} and
  5125. @code{LENGTH(@var{memory})} functions:
  5126. @smallexample
  5127. @group
  5128. _fstack = ORIGIN(ram) + LENGTH(ram) - 4;
  5129. @end group
  5130. @end smallexample
  5131. @node PHDRS
  5132. @section PHDRS Command
  5133. @kindex PHDRS
  5134. @cindex program headers
  5135. @cindex ELF program headers
  5136. @cindex program segments
  5137. @cindex segments, ELF
  5138. The ELF object file format uses @dfn{program headers}, also knows as
  5139. @dfn{segments}. The program headers describe how the program should be
  5140. loaded into memory. You can print them out by using the @code{objdump}
  5141. program with the @samp{-p} option.
  5142. When you run an ELF program on a native ELF system, the system loader
  5143. reads the program headers in order to figure out how to load the
  5144. program. This will only work if the program headers are set correctly.
  5145. This manual does not describe the details of how the system loader
  5146. interprets program headers; for more information, see the ELF ABI.
  5147. The linker will create reasonable program headers by default. However,
  5148. in some cases, you may need to specify the program headers more
  5149. precisely. You may use the @code{PHDRS} command for this purpose. When
  5150. the linker sees the @code{PHDRS} command in the linker script, it will
  5151. not create any program headers other than the ones specified.
  5152. The linker only pays attention to the @code{PHDRS} command when
  5153. generating an ELF output file. In other cases, the linker will simply
  5154. ignore @code{PHDRS}.
  5155. This is the syntax of the @code{PHDRS} command. The words @code{PHDRS},
  5156. @code{FILEHDR}, @code{AT}, and @code{FLAGS} are keywords.
  5157. @smallexample
  5158. @group
  5159. PHDRS
  5160. @{
  5161. @var{name} @var{type} [ FILEHDR ] [ PHDRS ] [ AT ( @var{address} ) ]
  5162. [ FLAGS ( @var{flags} ) ] ;
  5163. @}
  5164. @end group
  5165. @end smallexample
  5166. The @var{name} is used only for reference in the @code{SECTIONS} command
  5167. of the linker script. It is not put into the output file. Program
  5168. header names are stored in a separate name space, and will not conflict
  5169. with symbol names, file names, or section names. Each program header
  5170. must have a distinct name. The headers are processed in order and it
  5171. is usual for them to map to sections in ascending load address order.
  5172. Certain program header types describe segments of memory which the
  5173. system loader will load from the file. In the linker script, you
  5174. specify the contents of these segments by placing allocatable output
  5175. sections in the segments. You use the @samp{:@var{phdr}} output section
  5176. attribute to place a section in a particular segment. @xref{Output
  5177. Section Phdr}.
  5178. It is normal to put certain sections in more than one segment. This
  5179. merely implies that one segment of memory contains another. You may
  5180. repeat @samp{:@var{phdr}}, using it once for each segment which should
  5181. contain the section.
  5182. If you place a section in one or more segments using @samp{:@var{phdr}},
  5183. then the linker will place all subsequent allocatable sections which do
  5184. not specify @samp{:@var{phdr}} in the same segments. This is for
  5185. convenience, since generally a whole set of contiguous sections will be
  5186. placed in a single segment. You can use @code{:NONE} to override the
  5187. default segment and tell the linker to not put the section in any
  5188. segment at all.
  5189. @kindex FILEHDR
  5190. @kindex PHDRS
  5191. You may use the @code{FILEHDR} and @code{PHDRS} keywords after
  5192. the program header type to further describe the contents of the segment.
  5193. The @code{FILEHDR} keyword means that the segment should include the ELF
  5194. file header. The @code{PHDRS} keyword means that the segment should
  5195. include the ELF program headers themselves. If applied to a loadable
  5196. segment (@code{PT_LOAD}), all prior loadable segments must have one of
  5197. these keywords.
  5198. The @var{type} may be one of the following. The numbers indicate the
  5199. value of the keyword.
  5200. @table @asis
  5201. @item @code{PT_NULL} (0)
  5202. Indicates an unused program header.
  5203. @item @code{PT_LOAD} (1)
  5204. Indicates that this program header describes a segment to be loaded from
  5205. the file.
  5206. @item @code{PT_DYNAMIC} (2)
  5207. Indicates a segment where dynamic linking information can be found.
  5208. @item @code{PT_INTERP} (3)
  5209. Indicates a segment where the name of the program interpreter may be
  5210. found.
  5211. @item @code{PT_NOTE} (4)
  5212. Indicates a segment holding note information.
  5213. @item @code{PT_SHLIB} (5)
  5214. A reserved program header type, defined but not specified by the ELF
  5215. ABI.
  5216. @item @code{PT_PHDR} (6)
  5217. Indicates a segment where the program headers may be found.
  5218. @item @code{PT_TLS} (7)
  5219. Indicates a segment containing thread local storage.
  5220. @item @var{expression}
  5221. An expression giving the numeric type of the program header. This may
  5222. be used for types not defined above.
  5223. @end table
  5224. You can specify that a segment should be loaded at a particular address
  5225. in memory by using an @code{AT} expression. This is identical to the
  5226. @code{AT} command used as an output section attribute (@pxref{Output
  5227. Section LMA}). The @code{AT} command for a program header overrides the
  5228. output section attribute.
  5229. The linker will normally set the segment flags based on the sections
  5230. which comprise the segment. You may use the @code{FLAGS} keyword to
  5231. explicitly specify the segment flags. The value of @var{flags} must be
  5232. an integer. It is used to set the @code{p_flags} field of the program
  5233. header.
  5234. Here is an example of @code{PHDRS}. This shows a typical set of program
  5235. headers used on a native ELF system.
  5236. @example
  5237. @group
  5238. PHDRS
  5239. @{
  5240. headers PT_PHDR PHDRS ;
  5241. interp PT_INTERP ;
  5242. text PT_LOAD FILEHDR PHDRS ;
  5243. data PT_LOAD ;
  5244. dynamic PT_DYNAMIC ;
  5245. @}
  5246. SECTIONS
  5247. @{
  5248. . = SIZEOF_HEADERS;
  5249. .interp : @{ *(.interp) @} :text :interp
  5250. .text : @{ *(.text) @} :text
  5251. .rodata : @{ *(.rodata) @} /* defaults to :text */
  5252. @dots{}
  5253. . = . + 0x1000; /* move to a new page in memory */
  5254. .data : @{ *(.data) @} :data
  5255. .dynamic : @{ *(.dynamic) @} :data :dynamic
  5256. @dots{}
  5257. @}
  5258. @end group
  5259. @end example
  5260. @node VERSION
  5261. @section VERSION Command
  5262. @kindex VERSION @{script text@}
  5263. @cindex symbol versions
  5264. @cindex version script
  5265. @cindex versions of symbols
  5266. The linker supports symbol versions when using ELF. Symbol versions are
  5267. only useful when using shared libraries. The dynamic linker can use
  5268. symbol versions to select a specific version of a function when it runs
  5269. a program that may have been linked against an earlier version of the
  5270. shared library.
  5271. You can include a version script directly in the main linker script, or
  5272. you can supply the version script as an implicit linker script. You can
  5273. also use the @samp{--version-script} linker option.
  5274. The syntax of the @code{VERSION} command is simply
  5275. @smallexample
  5276. VERSION @{ version-script-commands @}
  5277. @end smallexample
  5278. The format of the version script commands is identical to that used by
  5279. Sun's linker in Solaris 2.5. The version script defines a tree of
  5280. version nodes. You specify the node names and interdependencies in the
  5281. version script. You can specify which symbols are bound to which
  5282. version nodes, and you can reduce a specified set of symbols to local
  5283. scope so that they are not globally visible outside of the shared
  5284. library.
  5285. The easiest way to demonstrate the version script language is with a few
  5286. examples.
  5287. @smallexample
  5288. VERS_1.1 @{
  5289. global:
  5290. foo1;
  5291. local:
  5292. old*;
  5293. original*;
  5294. new*;
  5295. @};
  5296. VERS_1.2 @{
  5297. foo2;
  5298. @} VERS_1.1;
  5299. VERS_2.0 @{
  5300. bar1; bar2;
  5301. extern "C++" @{
  5302. ns::*;
  5303. "f(int, double)";
  5304. @};
  5305. @} VERS_1.2;
  5306. @end smallexample
  5307. This example version script defines three version nodes. The first
  5308. version node defined is @samp{VERS_1.1}; it has no other dependencies.
  5309. The script binds the symbol @samp{foo1} to @samp{VERS_1.1}. It reduces
  5310. a number of symbols to local scope so that they are not visible outside
  5311. of the shared library; this is done using wildcard patterns, so that any
  5312. symbol whose name begins with @samp{old}, @samp{original}, or @samp{new}
  5313. is matched. The wildcard patterns available are the same as those used
  5314. in the shell when matching filenames (also known as ``globbing'').
  5315. However, if you specify the symbol name inside double quotes, then the
  5316. name is treated as literal, rather than as a glob pattern.
  5317. Next, the version script defines node @samp{VERS_1.2}. This node
  5318. depends upon @samp{VERS_1.1}. The script binds the symbol @samp{foo2}
  5319. to the version node @samp{VERS_1.2}.
  5320. Finally, the version script defines node @samp{VERS_2.0}. This node
  5321. depends upon @samp{VERS_1.2}. The scripts binds the symbols @samp{bar1}
  5322. and @samp{bar2} are bound to the version node @samp{VERS_2.0}.
  5323. When the linker finds a symbol defined in a library which is not
  5324. specifically bound to a version node, it will effectively bind it to an
  5325. unspecified base version of the library. You can bind all otherwise
  5326. unspecified symbols to a given version node by using @samp{global: *;}
  5327. somewhere in the version script. Note that it's slightly crazy to use
  5328. wildcards in a global spec except on the last version node. Global
  5329. wildcards elsewhere run the risk of accidentally adding symbols to the
  5330. set exported for an old version. That's wrong since older versions
  5331. ought to have a fixed set of symbols.
  5332. The names of the version nodes have no specific meaning other than what
  5333. they might suggest to the person reading them. The @samp{2.0} version
  5334. could just as well have appeared in between @samp{1.1} and @samp{1.2}.
  5335. However, this would be a confusing way to write a version script.
  5336. Node name can be omitted, provided it is the only version node
  5337. in the version script. Such version script doesn't assign any versions to
  5338. symbols, only selects which symbols will be globally visible out and which
  5339. won't.
  5340. @smallexample
  5341. @{ global: foo; bar; local: *; @};
  5342. @end smallexample
  5343. When you link an application against a shared library that has versioned
  5344. symbols, the application itself knows which version of each symbol it
  5345. requires, and it also knows which version nodes it needs from each
  5346. shared library it is linked against. Thus at runtime, the dynamic
  5347. loader can make a quick check to make sure that the libraries you have
  5348. linked against do in fact supply all of the version nodes that the
  5349. application will need to resolve all of the dynamic symbols. In this
  5350. way it is possible for the dynamic linker to know with certainty that
  5351. all external symbols that it needs will be resolvable without having to
  5352. search for each symbol reference.
  5353. The symbol versioning is in effect a much more sophisticated way of
  5354. doing minor version checking that SunOS does. The fundamental problem
  5355. that is being addressed here is that typically references to external
  5356. functions are bound on an as-needed basis, and are not all bound when
  5357. the application starts up. If a shared library is out of date, a
  5358. required interface may be missing; when the application tries to use
  5359. that interface, it may suddenly and unexpectedly fail. With symbol
  5360. versioning, the user will get a warning when they start their program if
  5361. the libraries being used with the application are too old.
  5362. There are several GNU extensions to Sun's versioning approach. The
  5363. first of these is the ability to bind a symbol to a version node in the
  5364. source file where the symbol is defined instead of in the versioning
  5365. script. This was done mainly to reduce the burden on the library
  5366. maintainer. You can do this by putting something like:
  5367. @smallexample
  5368. __asm__(".symver original_foo,foo@@VERS_1.1");
  5369. @end smallexample
  5370. @noindent
  5371. in the C source file. This renames the function @samp{original_foo} to
  5372. be an alias for @samp{foo} bound to the version node @samp{VERS_1.1}.
  5373. The @samp{local:} directive can be used to prevent the symbol
  5374. @samp{original_foo} from being exported. A @samp{.symver} directive
  5375. takes precedence over a version script.
  5376. The second GNU extension is to allow multiple versions of the same
  5377. function to appear in a given shared library. In this way you can make
  5378. an incompatible change to an interface without increasing the major
  5379. version number of the shared library, while still allowing applications
  5380. linked against the old interface to continue to function.
  5381. To do this, you must use multiple @samp{.symver} directives in the
  5382. source file. Here is an example:
  5383. @smallexample
  5384. __asm__(".symver original_foo,foo@@");
  5385. __asm__(".symver old_foo,foo@@VERS_1.1");
  5386. __asm__(".symver old_foo1,foo@@VERS_1.2");
  5387. __asm__(".symver new_foo,foo@@@@VERS_2.0");
  5388. @end smallexample
  5389. In this example, @samp{foo@@} represents the symbol @samp{foo} bound to the
  5390. unspecified base version of the symbol. The source file that contains this
  5391. example would define 4 C functions: @samp{original_foo}, @samp{old_foo},
  5392. @samp{old_foo1}, and @samp{new_foo}.
  5393. When you have multiple definitions of a given symbol, there needs to be
  5394. some way to specify a default version to which external references to
  5395. this symbol will be bound. You can do this with the
  5396. @samp{foo@@@@VERS_2.0} type of @samp{.symver} directive. You can only
  5397. declare one version of a symbol as the default in this manner; otherwise
  5398. you would effectively have multiple definitions of the same symbol.
  5399. If you wish to bind a reference to a specific version of the symbol
  5400. within the shared library, you can use the aliases of convenience
  5401. (i.e., @samp{old_foo}), or you can use the @samp{.symver} directive to
  5402. specifically bind to an external version of the function in question.
  5403. You can also specify the language in the version script:
  5404. @smallexample
  5405. VERSION extern "lang" @{ version-script-commands @}
  5406. @end smallexample
  5407. The supported @samp{lang}s are @samp{C}, @samp{C++}, and @samp{Java}.
  5408. The linker will iterate over the list of symbols at the link time and
  5409. demangle them according to @samp{lang} before matching them to the
  5410. patterns specified in @samp{version-script-commands}. The default
  5411. @samp{lang} is @samp{C}.
  5412. Demangled names may contains spaces and other special characters. As
  5413. described above, you can use a glob pattern to match demangled names,
  5414. or you can use a double-quoted string to match the string exactly. In
  5415. the latter case, be aware that minor differences (such as differing
  5416. whitespace) between the version script and the demangler output will
  5417. cause a mismatch. As the exact string generated by the demangler
  5418. might change in the future, even if the mangled name does not, you
  5419. should check that all of your version directives are behaving as you
  5420. expect when you upgrade.
  5421. @node Expressions
  5422. @section Expressions in Linker Scripts
  5423. @cindex expressions
  5424. @cindex arithmetic
  5425. The syntax for expressions in the linker script language is identical to
  5426. that of C expressions, except that whitespace is required in some
  5427. places to resolve syntactic ambiguities. All expressions are
  5428. evaluated as integers. All expressions are evaluated in the same
  5429. size, which is 32 bits if both the host and target are 32 bits, and is
  5430. otherwise 64 bits.
  5431. You can use and set symbol values in expressions.
  5432. The linker defines several special purpose builtin functions for use in
  5433. expressions.
  5434. @menu
  5435. * Constants:: Constants
  5436. * Symbolic Constants:: Symbolic constants
  5437. * Symbols:: Symbol Names
  5438. * Orphan Sections:: Orphan Sections
  5439. * Location Counter:: The Location Counter
  5440. * Operators:: Operators
  5441. * Evaluation:: Evaluation
  5442. * Expression Section:: The Section of an Expression
  5443. * Builtin Functions:: Builtin Functions
  5444. @end menu
  5445. @node Constants
  5446. @subsection Constants
  5447. @cindex integer notation
  5448. @cindex constants in linker scripts
  5449. All constants are integers.
  5450. As in C, the linker considers an integer beginning with @samp{0} to be
  5451. octal, and an integer beginning with @samp{0x} or @samp{0X} to be
  5452. hexadecimal. Alternatively the linker accepts suffixes of @samp{h} or
  5453. @samp{H} for hexadecimal, @samp{o} or @samp{O} for octal, @samp{b} or
  5454. @samp{B} for binary and @samp{d} or @samp{D} for decimal. Any integer
  5455. value without a prefix or a suffix is considered to be decimal.
  5456. @cindex scaled integers
  5457. @cindex K and M integer suffixes
  5458. @cindex M and K integer suffixes
  5459. @cindex suffixes for integers
  5460. @cindex integer suffixes
  5461. In addition, you can use the suffixes @code{K} and @code{M} to scale a
  5462. constant by
  5463. @c TEXI2ROFF-KILL
  5464. @ifnottex
  5465. @c END TEXI2ROFF-KILL
  5466. @code{1024} or @code{1024*1024}
  5467. @c TEXI2ROFF-KILL
  5468. @end ifnottex
  5469. @tex
  5470. ${\rm 1024}$ or ${\rm 1024}^2$
  5471. @end tex
  5472. @c END TEXI2ROFF-KILL
  5473. respectively. For example, the following
  5474. all refer to the same quantity:
  5475. @smallexample
  5476. _fourk_1 = 4K;
  5477. _fourk_2 = 4096;
  5478. _fourk_3 = 0x1000;
  5479. _fourk_4 = 10000o;
  5480. @end smallexample
  5481. Note - the @code{K} and @code{M} suffixes cannot be used in
  5482. conjunction with the base suffixes mentioned above.
  5483. @node Symbolic Constants
  5484. @subsection Symbolic Constants
  5485. @cindex symbolic constants
  5486. @kindex CONSTANT
  5487. It is possible to refer to target-specific constants via the use of
  5488. the @code{CONSTANT(@var{name})} operator, where @var{name} is one of:
  5489. @table @code
  5490. @item MAXPAGESIZE
  5491. @kindex MAXPAGESIZE
  5492. The target's maximum page size.
  5493. @item COMMONPAGESIZE
  5494. @kindex COMMONPAGESIZE
  5495. The target's default page size.
  5496. @end table
  5497. So for example:
  5498. @smallexample
  5499. .text ALIGN (CONSTANT (MAXPAGESIZE)) : @{ *(.text) @}
  5500. @end smallexample
  5501. will create a text section aligned to the largest page boundary
  5502. supported by the target.
  5503. @node Symbols
  5504. @subsection Symbol Names
  5505. @cindex symbol names
  5506. @cindex names
  5507. @cindex quoted symbol names
  5508. @kindex "
  5509. Unless quoted, symbol names start with a letter, underscore, or period
  5510. and may include letters, digits, underscores, periods, and hyphens.
  5511. Unquoted symbol names must not conflict with any keywords. You can
  5512. specify a symbol which contains odd characters or has the same name as a
  5513. keyword by surrounding the symbol name in double quotes:
  5514. @smallexample
  5515. "SECTION" = 9;
  5516. "with a space" = "also with a space" + 10;
  5517. @end smallexample
  5518. Since symbols can contain many non-alphabetic characters, it is safest
  5519. to delimit symbols with spaces. For example, @samp{A-B} is one symbol,
  5520. whereas @samp{A - B} is an expression involving subtraction.
  5521. @node Orphan Sections
  5522. @subsection Orphan Sections
  5523. @cindex orphan
  5524. Orphan sections are sections present in the input files which
  5525. are not explicitly placed into the output file by the linker
  5526. script. The linker will still copy these sections into the
  5527. output file by either finding, or creating a suitable output section
  5528. in which to place the orphaned input section.
  5529. If the name of an orphaned input section exactly matches the name of
  5530. an existing output section, then the orphaned input section will be
  5531. placed at the end of that output section.
  5532. If there is no output section with a matching name then new output
  5533. sections will be created. Each new output section will have the same
  5534. name as the orphan section placed within it. If there are multiple
  5535. orphan sections with the same name, these will all be combined into
  5536. one new output section.
  5537. If new output sections are created to hold orphaned input sections,
  5538. then the linker must decide where to place these new output sections
  5539. in relation to existing output sections. On most modern targets, the
  5540. linker attempts to place orphan sections after sections of the same
  5541. attribute, such as code vs data, loadable vs non-loadable, etc. If no
  5542. sections with matching attributes are found, or your target lacks this
  5543. support, the orphan section is placed at the end of the file.
  5544. The command-line options @samp{--orphan-handling} and @samp{--unique}
  5545. (@pxref{Options,,Command-line Options}) can be used to control which
  5546. output sections an orphan is placed in.
  5547. @node Location Counter
  5548. @subsection The Location Counter
  5549. @kindex .
  5550. @cindex dot
  5551. @cindex location counter
  5552. @cindex current output location
  5553. The special linker variable @dfn{dot} @samp{.} always contains the
  5554. current output location counter. Since the @code{.} always refers to a
  5555. location in an output section, it may only appear in an expression
  5556. within a @code{SECTIONS} command. The @code{.} symbol may appear
  5557. anywhere that an ordinary symbol is allowed in an expression.
  5558. @cindex holes
  5559. Assigning a value to @code{.} will cause the location counter to be
  5560. moved. This may be used to create holes in the output section. The
  5561. location counter may not be moved backwards inside an output section,
  5562. and may not be moved backwards outside of an output section if so
  5563. doing creates areas with overlapping LMAs.
  5564. @smallexample
  5565. SECTIONS
  5566. @{
  5567. output :
  5568. @{
  5569. file1(.text)
  5570. . = . + 1000;
  5571. file2(.text)
  5572. . += 1000;
  5573. file3(.text)
  5574. @} = 0x12345678;
  5575. @}
  5576. @end smallexample
  5577. @noindent
  5578. In the previous example, the @samp{.text} section from @file{file1} is
  5579. located at the beginning of the output section @samp{output}. It is
  5580. followed by a 1000 byte gap. Then the @samp{.text} section from
  5581. @file{file2} appears, also with a 1000 byte gap following before the
  5582. @samp{.text} section from @file{file3}. The notation @samp{= 0x12345678}
  5583. specifies what data to write in the gaps (@pxref{Output Section Fill}).
  5584. @cindex dot inside sections
  5585. Note: @code{.} actually refers to the byte offset from the start of the
  5586. current containing object. Normally this is the @code{SECTIONS}
  5587. statement, whose start address is 0, hence @code{.} can be used as an
  5588. absolute address. If @code{.} is used inside a section description
  5589. however, it refers to the byte offset from the start of that section,
  5590. not an absolute address. Thus in a script like this:
  5591. @smallexample
  5592. SECTIONS
  5593. @{
  5594. . = 0x100
  5595. .text: @{
  5596. *(.text)
  5597. . = 0x200
  5598. @}
  5599. . = 0x500
  5600. .data: @{
  5601. *(.data)
  5602. . += 0x600
  5603. @}
  5604. @}
  5605. @end smallexample
  5606. The @samp{.text} section will be assigned a starting address of 0x100
  5607. and a size of exactly 0x200 bytes, even if there is not enough data in
  5608. the @samp{.text} input sections to fill this area. (If there is too
  5609. much data, an error will be produced because this would be an attempt to
  5610. move @code{.} backwards). The @samp{.data} section will start at 0x500
  5611. and it will have an extra 0x600 bytes worth of space after the end of
  5612. the values from the @samp{.data} input sections and before the end of
  5613. the @samp{.data} output section itself.
  5614. @cindex dot outside sections
  5615. Setting symbols to the value of the location counter outside of an
  5616. output section statement can result in unexpected values if the linker
  5617. needs to place orphan sections. For example, given the following:
  5618. @smallexample
  5619. SECTIONS
  5620. @{
  5621. start_of_text = . ;
  5622. .text: @{ *(.text) @}
  5623. end_of_text = . ;
  5624. start_of_data = . ;
  5625. .data: @{ *(.data) @}
  5626. end_of_data = . ;
  5627. @}
  5628. @end smallexample
  5629. If the linker needs to place some input section, e.g. @code{.rodata},
  5630. not mentioned in the script, it might choose to place that section
  5631. between @code{.text} and @code{.data}. You might think the linker
  5632. should place @code{.rodata} on the blank line in the above script, but
  5633. blank lines are of no particular significance to the linker. As well,
  5634. the linker doesn't associate the above symbol names with their
  5635. sections. Instead, it assumes that all assignments or other
  5636. statements belong to the previous output section, except for the
  5637. special case of an assignment to @code{.}. I.e., the linker will
  5638. place the orphan @code{.rodata} section as if the script was written
  5639. as follows:
  5640. @smallexample
  5641. SECTIONS
  5642. @{
  5643. start_of_text = . ;
  5644. .text: @{ *(.text) @}
  5645. end_of_text = . ;
  5646. start_of_data = . ;
  5647. .rodata: @{ *(.rodata) @}
  5648. .data: @{ *(.data) @}
  5649. end_of_data = . ;
  5650. @}
  5651. @end smallexample
  5652. This may or may not be the script author's intention for the value of
  5653. @code{start_of_data}. One way to influence the orphan section
  5654. placement is to assign the location counter to itself, as the linker
  5655. assumes that an assignment to @code{.} is setting the start address of
  5656. a following output section and thus should be grouped with that
  5657. section. So you could write:
  5658. @smallexample
  5659. SECTIONS
  5660. @{
  5661. start_of_text = . ;
  5662. .text: @{ *(.text) @}
  5663. end_of_text = . ;
  5664. . = . ;
  5665. start_of_data = . ;
  5666. .data: @{ *(.data) @}
  5667. end_of_data = . ;
  5668. @}
  5669. @end smallexample
  5670. Now, the orphan @code{.rodata} section will be placed between
  5671. @code{end_of_text} and @code{start_of_data}.
  5672. @need 2000
  5673. @node Operators
  5674. @subsection Operators
  5675. @cindex operators for arithmetic
  5676. @cindex arithmetic operators
  5677. @cindex precedence in expressions
  5678. The linker recognizes the standard C set of arithmetic operators, with
  5679. the standard bindings and precedence levels:
  5680. @c TEXI2ROFF-KILL
  5681. @ifnottex
  5682. @c END TEXI2ROFF-KILL
  5683. @smallexample
  5684. precedence associativity Operators Notes
  5685. (highest)
  5686. 1 left ! - ~ (1)
  5687. 2 left * / %
  5688. 3 left + -
  5689. 4 left >> <<
  5690. 5 left == != > < <= >=
  5691. 6 left &
  5692. 7 left |
  5693. 8 left &&
  5694. 9 left ||
  5695. 10 right ? :
  5696. 11 right &= += -= *= /= (2)
  5697. (lowest)
  5698. @end smallexample
  5699. Notes:
  5700. (1) Prefix operators
  5701. (2) @xref{Assignments}.
  5702. @c TEXI2ROFF-KILL
  5703. @end ifnottex
  5704. @tex
  5705. \vskip \baselineskip
  5706. %"lispnarrowing" is the extra indent used generally for smallexample
  5707. \hskip\lispnarrowing\vbox{\offinterlineskip
  5708. \hrule
  5709. \halign
  5710. {\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ {\tt #}\ \hfil&\vrule#\cr
  5711. height2pt&\omit&&\omit&&\omit&\cr
  5712. &Precedence&& Associativity &&{\rm Operators}&\cr
  5713. height2pt&\omit&&\omit&&\omit&\cr
  5714. \noalign{\hrule}
  5715. height2pt&\omit&&\omit&&\omit&\cr
  5716. &highest&&&&&\cr
  5717. % '176 is tilde, '~' in tt font
  5718. &1&&left&&\qquad- \char'176\ !\qquad\dag&\cr
  5719. &2&&left&&* / \%&\cr
  5720. &3&&left&&+ -&\cr
  5721. &4&&left&&>> <<&\cr
  5722. &5&&left&&== != > < <= >=&\cr
  5723. &6&&left&&\&&\cr
  5724. &7&&left&&|&\cr
  5725. &8&&left&&{\&\&}&\cr
  5726. &9&&left&&||&\cr
  5727. &10&&right&&? :&\cr
  5728. &11&&right&&\qquad\&= += -= *= /=\qquad\ddag&\cr
  5729. &lowest&&&&&\cr
  5730. height2pt&\omit&&\omit&&\omit&\cr}
  5731. \hrule}
  5732. @end tex
  5733. @iftex
  5734. {
  5735. @obeylines@parskip=0pt@parindent=0pt
  5736. @dag@quad Prefix operators.
  5737. @ddag@quad @xref{Assignments}.
  5738. }
  5739. @end iftex
  5740. @c END TEXI2ROFF-KILL
  5741. @node Evaluation
  5742. @subsection Evaluation
  5743. @cindex lazy evaluation
  5744. @cindex expression evaluation order
  5745. The linker evaluates expressions lazily. It only computes the value of
  5746. an expression when absolutely necessary.
  5747. The linker needs some information, such as the value of the start
  5748. address of the first section, and the origins and lengths of memory
  5749. regions, in order to do any linking at all. These values are computed
  5750. as soon as possible when the linker reads in the linker script.
  5751. However, other values (such as symbol values) are not known or needed
  5752. until after storage allocation. Such values are evaluated later, when
  5753. other information (such as the sizes of output sections) is available
  5754. for use in the symbol assignment expression.
  5755. The sizes of sections cannot be known until after allocation, so
  5756. assignments dependent upon these are not performed until after
  5757. allocation.
  5758. Some expressions, such as those depending upon the location counter
  5759. @samp{.}, must be evaluated during section allocation.
  5760. If the result of an expression is required, but the value is not
  5761. available, then an error results. For example, a script like the
  5762. following
  5763. @smallexample
  5764. @group
  5765. SECTIONS
  5766. @{
  5767. .text 9+this_isnt_constant :
  5768. @{ *(.text) @}
  5769. @}
  5770. @end group
  5771. @end smallexample
  5772. @noindent
  5773. will cause the error message @samp{non constant expression for initial
  5774. address}.
  5775. @node Expression Section
  5776. @subsection The Section of an Expression
  5777. @cindex expression sections
  5778. @cindex absolute expressions
  5779. @cindex relative expressions
  5780. @cindex absolute and relocatable symbols
  5781. @cindex relocatable and absolute symbols
  5782. @cindex symbols, relocatable and absolute
  5783. Addresses and symbols may be section relative, or absolute. A section
  5784. relative symbol is relocatable. If you request relocatable output
  5785. using the @samp{-r} option, a further link operation may change the
  5786. value of a section relative symbol. On the other hand, an absolute
  5787. symbol will retain the same value throughout any further link
  5788. operations.
  5789. Some terms in linker expressions are addresses. This is true of
  5790. section relative symbols and for builtin functions that return an
  5791. address, such as @code{ADDR}, @code{LOADADDR}, @code{ORIGIN} and
  5792. @code{SEGMENT_START}. Other terms are simply numbers, or are builtin
  5793. functions that return a non-address value, such as @code{LENGTH}.
  5794. One complication is that unless you set @code{LD_FEATURE ("SANE_EXPR")}
  5795. (@pxref{Miscellaneous Commands}), numbers and absolute symbols are treated
  5796. differently depending on their location, for compatibility with older
  5797. versions of @code{ld}. Expressions appearing outside an output
  5798. section definition treat all numbers as absolute addresses.
  5799. Expressions appearing inside an output section definition treat
  5800. absolute symbols as numbers. If @code{LD_FEATURE ("SANE_EXPR")} is
  5801. given, then absolute symbols and numbers are simply treated as numbers
  5802. everywhere.
  5803. In the following simple example,
  5804. @smallexample
  5805. @group
  5806. SECTIONS
  5807. @{
  5808. . = 0x100;
  5809. __executable_start = 0x100;
  5810. .data :
  5811. @{
  5812. . = 0x10;
  5813. __data_start = 0x10;
  5814. *(.data)
  5815. @}
  5816. @dots{}
  5817. @}
  5818. @end group
  5819. @end smallexample
  5820. both @code{.} and @code{__executable_start} are set to the absolute
  5821. address 0x100 in the first two assignments, then both @code{.} and
  5822. @code{__data_start} are set to 0x10 relative to the @code{.data}
  5823. section in the second two assignments.
  5824. For expressions involving numbers, relative addresses and absolute
  5825. addresses, ld follows these rules to evaluate terms:
  5826. @itemize @bullet
  5827. @item
  5828. Unary operations on an absolute address or number, and binary
  5829. operations on two absolute addresses or two numbers, or between one
  5830. absolute address and a number, apply the operator to the value(s).
  5831. @item
  5832. Unary operations on a relative address, and binary operations on two
  5833. relative addresses in the same section or between one relative address
  5834. and a number, apply the operator to the offset part of the address(es).
  5835. @item
  5836. Other binary operations, that is, between two relative addresses not
  5837. in the same section, or between a relative address and an absolute
  5838. address, first convert any non-absolute term to an absolute address
  5839. before applying the operator.
  5840. @end itemize
  5841. The result section of each sub-expression is as follows:
  5842. @itemize @bullet
  5843. @item
  5844. An operation involving only numbers results in a number.
  5845. @item
  5846. The result of comparisons, @samp{&&} and @samp{||} is also a number.
  5847. @item
  5848. The result of other binary arithmetic and logical operations on two
  5849. relative addresses in the same section or two absolute addresses
  5850. (after above conversions) is also a number when
  5851. @code{LD_FEATURE ("SANE_EXPR")} or inside an output section definition
  5852. but an absolute address otherwise.
  5853. @item
  5854. The result of other operations on relative addresses or one
  5855. relative address and a number, is a relative address in the same
  5856. section as the relative operand(s).
  5857. @item
  5858. The result of other operations on absolute addresses (after above
  5859. conversions) is an absolute address.
  5860. @end itemize
  5861. You can use the builtin function @code{ABSOLUTE} to force an expression
  5862. to be absolute when it would otherwise be relative. For example, to
  5863. create an absolute symbol set to the address of the end of the output
  5864. section @samp{.data}:
  5865. @smallexample
  5866. SECTIONS
  5867. @{
  5868. .data : @{ *(.data) _edata = ABSOLUTE(.); @}
  5869. @}
  5870. @end smallexample
  5871. @noindent
  5872. If @samp{ABSOLUTE} were not used, @samp{_edata} would be relative to the
  5873. @samp{.data} section.
  5874. Using @code{LOADADDR} also forces an expression absolute, since this
  5875. particular builtin function returns an absolute address.
  5876. @node Builtin Functions
  5877. @subsection Builtin Functions
  5878. @cindex functions in expressions
  5879. The linker script language includes a number of builtin functions for
  5880. use in linker script expressions.
  5881. @table @code
  5882. @item ABSOLUTE(@var{exp})
  5883. @kindex ABSOLUTE(@var{exp})
  5884. @cindex expression, absolute
  5885. Return the absolute (non-relocatable, as opposed to non-negative) value
  5886. of the expression @var{exp}. Primarily useful to assign an absolute
  5887. value to a symbol within a section definition, where symbol values are
  5888. normally section relative. @xref{Expression Section}.
  5889. @item ADDR(@var{section})
  5890. @kindex ADDR(@var{section})
  5891. @cindex section address in expression
  5892. Return the address (VMA) of the named @var{section}. Your
  5893. script must previously have defined the location of that section. In
  5894. the following example, @code{start_of_output_1}, @code{symbol_1} and
  5895. @code{symbol_2} are assigned equivalent values, except that
  5896. @code{symbol_1} will be relative to the @code{.output1} section while
  5897. the other two will be absolute:
  5898. @smallexample
  5899. @group
  5900. SECTIONS @{ @dots{}
  5901. .output1 :
  5902. @{
  5903. start_of_output_1 = ABSOLUTE(.);
  5904. @dots{}
  5905. @}
  5906. .output :
  5907. @{
  5908. symbol_1 = ADDR(.output1);
  5909. symbol_2 = start_of_output_1;
  5910. @}
  5911. @dots{} @}
  5912. @end group
  5913. @end smallexample
  5914. @item ALIGN(@var{align})
  5915. @itemx ALIGN(@var{exp},@var{align})
  5916. @kindex ALIGN(@var{align})
  5917. @kindex ALIGN(@var{exp},@var{align})
  5918. @cindex round up location counter
  5919. @cindex align location counter
  5920. @cindex round up expression
  5921. @cindex align expression
  5922. Return the location counter (@code{.}) or arbitrary expression aligned
  5923. to the next @var{align} boundary. The single operand @code{ALIGN}
  5924. doesn't change the value of the location counter---it just does
  5925. arithmetic on it. The two operand @code{ALIGN} allows an arbitrary
  5926. expression to be aligned upwards (@code{ALIGN(@var{align})} is
  5927. equivalent to @code{ALIGN(ABSOLUTE(.), @var{align})}).
  5928. Here is an example which aligns the output @code{.data} section to the
  5929. next @code{0x2000} byte boundary after the preceding section and sets a
  5930. variable within the section to the next @code{0x8000} boundary after the
  5931. input sections:
  5932. @smallexample
  5933. @group
  5934. SECTIONS @{ @dots{}
  5935. .data ALIGN(0x2000): @{
  5936. *(.data)
  5937. variable = ALIGN(0x8000);
  5938. @}
  5939. @dots{} @}
  5940. @end group
  5941. @end smallexample
  5942. @noindent
  5943. The first use of @code{ALIGN} in this example specifies the location of
  5944. a section because it is used as the optional @var{address} attribute of
  5945. a section definition (@pxref{Output Section Address}). The second use
  5946. of @code{ALIGN} is used to defines the value of a symbol.
  5947. The builtin function @code{NEXT} is closely related to @code{ALIGN}.
  5948. @item ALIGNOF(@var{section})
  5949. @kindex ALIGNOF(@var{section})
  5950. @cindex section alignment
  5951. Return the alignment in bytes of the named @var{section}, if that section has
  5952. been allocated. If the section has not been allocated when this is
  5953. evaluated, the linker will report an error. In the following example,
  5954. the alignment of the @code{.output} section is stored as the first
  5955. value in that section.
  5956. @smallexample
  5957. @group
  5958. SECTIONS@{ @dots{}
  5959. .output @{
  5960. LONG (ALIGNOF (.output))
  5961. @dots{}
  5962. @}
  5963. @dots{} @}
  5964. @end group
  5965. @end smallexample
  5966. @item BLOCK(@var{exp})
  5967. @kindex BLOCK(@var{exp})
  5968. This is a synonym for @code{ALIGN}, for compatibility with older linker
  5969. scripts. It is most often seen when setting the address of an output
  5970. section.
  5971. @item DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize})
  5972. @kindex DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize})
  5973. This is equivalent to either
  5974. @smallexample
  5975. (ALIGN(@var{maxpagesize}) + (. & (@var{maxpagesize} - 1)))
  5976. @end smallexample
  5977. or
  5978. @smallexample
  5979. (ALIGN(@var{maxpagesize})
  5980. + ((. + @var{commonpagesize} - 1) & (@var{maxpagesize} - @var{commonpagesize})))
  5981. @end smallexample
  5982. @noindent
  5983. depending on whether the latter uses fewer @var{commonpagesize} sized pages
  5984. for the data segment (area between the result of this expression and
  5985. @code{DATA_SEGMENT_END}) than the former or not.
  5986. If the latter form is used, it means @var{commonpagesize} bytes of runtime
  5987. memory will be saved at the expense of up to @var{commonpagesize} wasted
  5988. bytes in the on-disk file.
  5989. This expression can only be used directly in @code{SECTIONS} commands, not in
  5990. any output section descriptions and only once in the linker script.
  5991. @var{commonpagesize} should be less or equal to @var{maxpagesize} and should
  5992. be the system page size the object wants to be optimized for while still
  5993. running on system page sizes up to @var{maxpagesize}. Note however
  5994. that @samp{-z relro} protection will not be effective if the system
  5995. page size is larger than @var{commonpagesize}.
  5996. @noindent
  5997. Example:
  5998. @smallexample
  5999. . = DATA_SEGMENT_ALIGN(0x10000, 0x2000);
  6000. @end smallexample
  6001. @item DATA_SEGMENT_END(@var{exp})
  6002. @kindex DATA_SEGMENT_END(@var{exp})
  6003. This defines the end of data segment for @code{DATA_SEGMENT_ALIGN}
  6004. evaluation purposes.
  6005. @smallexample
  6006. . = DATA_SEGMENT_END(.);
  6007. @end smallexample
  6008. @item DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
  6009. @kindex DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
  6010. This defines the end of the @code{PT_GNU_RELRO} segment when
  6011. @samp{-z relro} option is used.
  6012. When @samp{-z relro} option is not present, @code{DATA_SEGMENT_RELRO_END}
  6013. does nothing, otherwise @code{DATA_SEGMENT_ALIGN} is padded so that
  6014. @var{exp} + @var{offset} is aligned to the @var{commonpagesize}
  6015. argument given to @code{DATA_SEGMENT_ALIGN}. If present in the linker
  6016. script, it must be placed between @code{DATA_SEGMENT_ALIGN} and
  6017. @code{DATA_SEGMENT_END}. Evaluates to the second argument plus any
  6018. padding needed at the end of the @code{PT_GNU_RELRO} segment due to
  6019. section alignment.
  6020. @smallexample
  6021. . = DATA_SEGMENT_RELRO_END(24, .);
  6022. @end smallexample
  6023. @item DEFINED(@var{symbol})
  6024. @kindex DEFINED(@var{symbol})
  6025. @cindex symbol defaults
  6026. Return 1 if @var{symbol} is in the linker global symbol table and is
  6027. defined before the statement using DEFINED in the script, otherwise
  6028. return 0. You can use this function to provide
  6029. default values for symbols. For example, the following script fragment
  6030. shows how to set a global symbol @samp{begin} to the first location in
  6031. the @samp{.text} section---but if a symbol called @samp{begin} already
  6032. existed, its value is preserved:
  6033. @smallexample
  6034. @group
  6035. SECTIONS @{ @dots{}
  6036. .text : @{
  6037. begin = DEFINED(begin) ? begin : . ;
  6038. @dots{}
  6039. @}
  6040. @dots{}
  6041. @}
  6042. @end group
  6043. @end smallexample
  6044. @item LENGTH(@var{memory})
  6045. @kindex LENGTH(@var{memory})
  6046. Return the length of the memory region named @var{memory}.
  6047. @item LOADADDR(@var{section})
  6048. @kindex LOADADDR(@var{section})
  6049. @cindex section load address in expression
  6050. Return the absolute LMA of the named @var{section}. (@pxref{Output
  6051. Section LMA}).
  6052. @item LOG2CEIL(@var{exp})
  6053. @kindex LOG2CEIL(@var{exp})
  6054. Return the binary logarithm of @var{exp} rounded towards infinity.
  6055. @code{LOG2CEIL(0)} returns 0.
  6056. @kindex MAX
  6057. @item MAX(@var{exp1}, @var{exp2})
  6058. Returns the maximum of @var{exp1} and @var{exp2}.
  6059. @kindex MIN
  6060. @item MIN(@var{exp1}, @var{exp2})
  6061. Returns the minimum of @var{exp1} and @var{exp2}.
  6062. @item NEXT(@var{exp})
  6063. @kindex NEXT(@var{exp})
  6064. @cindex unallocated address, next
  6065. Return the next unallocated address that is a multiple of @var{exp}.
  6066. This function is closely related to @code{ALIGN(@var{exp})}; unless you
  6067. use the @code{MEMORY} command to define discontinuous memory for the
  6068. output file, the two functions are equivalent.
  6069. @item ORIGIN(@var{memory})
  6070. @kindex ORIGIN(@var{memory})
  6071. Return the origin of the memory region named @var{memory}.
  6072. @item SEGMENT_START(@var{segment}, @var{default})
  6073. @kindex SEGMENT_START(@var{segment}, @var{default})
  6074. Return the base address of the named @var{segment}. If an explicit
  6075. value has already been given for this segment (with a command-line
  6076. @samp{-T} option) then that value will be returned otherwise the value
  6077. will be @var{default}. At present, the @samp{-T} command-line option
  6078. can only be used to set the base address for the ``text'', ``data'', and
  6079. ``bss'' sections, but you can use @code{SEGMENT_START} with any segment
  6080. name.
  6081. @item SIZEOF(@var{section})
  6082. @kindex SIZEOF(@var{section})
  6083. @cindex section size
  6084. Return the size in bytes of the named @var{section}, if that section has
  6085. been allocated. If the section has not been allocated when this is
  6086. evaluated, the linker will report an error. In the following example,
  6087. @code{symbol_1} and @code{symbol_2} are assigned identical values:
  6088. @smallexample
  6089. @group
  6090. SECTIONS@{ @dots{}
  6091. .output @{
  6092. .start = . ;
  6093. @dots{}
  6094. .end = . ;
  6095. @}
  6096. symbol_1 = .end - .start ;
  6097. symbol_2 = SIZEOF(.output);
  6098. @dots{} @}
  6099. @end group
  6100. @end smallexample
  6101. @item SIZEOF_HEADERS
  6102. @kindex SIZEOF_HEADERS
  6103. @cindex header size
  6104. Return the size in bytes of the output file's headers. This is
  6105. information which appears at the start of the output file. You can use
  6106. this number when setting the start address of the first section, if you
  6107. choose, to facilitate paging.
  6108. @cindex not enough room for program headers
  6109. @cindex program headers, not enough room
  6110. When producing an ELF output file, if the linker script uses the
  6111. @code{SIZEOF_HEADERS} builtin function, the linker must compute the
  6112. number of program headers before it has determined all the section
  6113. addresses and sizes. If the linker later discovers that it needs
  6114. additional program headers, it will report an error @samp{not enough
  6115. room for program headers}. To avoid this error, you must avoid using
  6116. the @code{SIZEOF_HEADERS} function, or you must rework your linker
  6117. script to avoid forcing the linker to use additional program headers, or
  6118. you must define the program headers yourself using the @code{PHDRS}
  6119. command (@pxref{PHDRS}).
  6120. @end table
  6121. @node Implicit Linker Scripts
  6122. @section Implicit Linker Scripts
  6123. @cindex implicit linker scripts
  6124. If you specify a linker input file which the linker can not recognize as
  6125. an object file or an archive file, it will try to read the file as a
  6126. linker script. If the file can not be parsed as a linker script, the
  6127. linker will report an error.
  6128. An implicit linker script will not replace the default linker script.
  6129. Typically an implicit linker script would contain only symbol
  6130. assignments, or the @code{INPUT}, @code{GROUP}, or @code{VERSION}
  6131. commands.
  6132. Any input files read because of an implicit linker script will be read
  6133. at the position in the command line where the implicit linker script was
  6134. read. This can affect archive searching.
  6135. @node Plugins
  6136. @chapter Linker Plugins
  6137. @cindex plugins
  6138. @cindex linker plugins
  6139. The linker can use dynamically loaded plugins to modify its behavior.
  6140. For example, the link-time optimization feature that some compilers
  6141. support is implemented with a linker plugin.
  6142. Currently there is only one plugin shipped by default, but more may
  6143. be added here later.
  6144. @menu
  6145. * libdep Plugin:: Static Library Dependencies Plugin
  6146. @end menu
  6147. @node libdep Plugin
  6148. @section Static Library Dependencies Plugin
  6149. @cindex static library dependencies
  6150. Originally, static libraries were contained in an archive file consisting
  6151. just of a collection of relocatable object files. Later they evolved to
  6152. optionally include a symbol table, to assist in finding the needed objects
  6153. within a library. There their evolution ended, and dynamic libraries
  6154. rose to ascendance.
  6155. One useful feature of dynamic libraries was that, more than just collecting
  6156. multiple objects into a single file, they also included a list of their
  6157. dependencies, such that one could specify just the name of a single dynamic
  6158. library at link time, and all of its dependencies would be implicitly
  6159. referenced as well. But static libraries lacked this feature, so if a
  6160. link invocation was switched from using dynamic libraries to static
  6161. libraries, the link command would usually fail unless it was rewritten to
  6162. explicitly list the dependencies of the static library.
  6163. The GNU @command{ar} utility now supports a @option{--record-libdeps} option
  6164. to embed dependency lists into static libraries as well, and the @file{libdep}
  6165. plugin may be used to read this dependency information at link time. The
  6166. dependency information is stored as a single string, carrying @option{-l}
  6167. and @option{-L} arguments as they would normally appear in a linker
  6168. command line. As such, the information can be written with any text
  6169. utility and stored into any archive, even if GNU @command{ar} is not
  6170. being used to create the archive. The information is stored in an
  6171. archive member named @samp{__.LIBDEP}.
  6172. For example, given a library @file{libssl.a} that depends on another
  6173. library @file{libcrypto.a} which may be found in @file{/usr/local/lib},
  6174. the @samp{__.LIBDEP} member of @file{libssl.a} would contain
  6175. @smallexample
  6176. -L/usr/local/lib -lcrypto
  6177. @end smallexample
  6178. @ifset GENERIC
  6179. @node Machine Dependent
  6180. @chapter Machine Dependent Features
  6181. @cindex machine dependencies
  6182. @command{ld} has additional features on some platforms; the following
  6183. sections describe them. Machines where @command{ld} has no additional
  6184. functionality are not listed.
  6185. @menu
  6186. @ifset H8300
  6187. * H8/300:: @command{ld} and the H8/300
  6188. @end ifset
  6189. @ifset M68HC11
  6190. * M68HC11/68HC12:: @code{ld} and the Motorola 68HC11 and 68HC12 families
  6191. @end ifset
  6192. @ifset ARM
  6193. * ARM:: @command{ld} and the ARM family
  6194. @end ifset
  6195. @ifset HPPA
  6196. * HPPA ELF32:: @command{ld} and HPPA 32-bit ELF
  6197. @end ifset
  6198. @ifset M68K
  6199. * M68K:: @command{ld} and the Motorola 68K family
  6200. @end ifset
  6201. @ifset MIPS
  6202. * MIPS:: @command{ld} and the MIPS family
  6203. @end ifset
  6204. @ifset MMIX
  6205. * MMIX:: @command{ld} and MMIX
  6206. @end ifset
  6207. @ifset MSP430
  6208. * MSP430:: @command{ld} and MSP430
  6209. @end ifset
  6210. @ifset NDS32
  6211. * NDS32:: @command{ld} and NDS32
  6212. @end ifset
  6213. @ifset NIOSII
  6214. * Nios II:: @command{ld} and the Altera Nios II
  6215. @end ifset
  6216. @ifset POWERPC
  6217. * PowerPC ELF32:: @command{ld} and PowerPC 32-bit ELF Support
  6218. @end ifset
  6219. @ifset POWERPC64
  6220. * PowerPC64 ELF64:: @command{ld} and PowerPC64 64-bit ELF Support
  6221. @end ifset
  6222. @ifset S/390
  6223. * S/390 ELF:: @command{ld} and S/390 ELF Support
  6224. @end ifset
  6225. @ifset SPU
  6226. * SPU ELF:: @command{ld} and SPU ELF Support
  6227. @end ifset
  6228. @ifset TICOFF
  6229. * TI COFF:: @command{ld} and TI COFF
  6230. @end ifset
  6231. @ifset WIN32
  6232. * WIN32:: @command{ld} and WIN32 (cygwin/mingw)
  6233. @end ifset
  6234. @ifset XTENSA
  6235. * Xtensa:: @command{ld} and Xtensa Processors
  6236. @end ifset
  6237. @end menu
  6238. @end ifset
  6239. @ifset H8300
  6240. @ifclear GENERIC
  6241. @raisesections
  6242. @end ifclear
  6243. @node H8/300
  6244. @section @command{ld} and the H8/300
  6245. @cindex H8/300 support
  6246. For the H8/300, @command{ld} can perform these global optimizations when
  6247. you specify the @samp{--relax} command-line option.
  6248. @table @emph
  6249. @cindex relaxing on H8/300
  6250. @item relaxing address modes
  6251. @command{ld} finds all @code{jsr} and @code{jmp} instructions whose
  6252. targets are within eight bits, and turns them into eight-bit
  6253. program-counter relative @code{bsr} and @code{bra} instructions,
  6254. respectively.
  6255. @cindex synthesizing on H8/300
  6256. @item synthesizing instructions
  6257. @c FIXME: specifically mov.b, or any mov instructions really? -> mov.b only, at least on H8, H8H, H8S
  6258. @command{ld} finds all @code{mov.b} instructions which use the
  6259. sixteen-bit absolute address form, but refer to the top
  6260. page of memory, and changes them to use the eight-bit address form.
  6261. (That is: the linker turns @samp{mov.b @code{@@}@var{aa}:16} into
  6262. @samp{mov.b @code{@@}@var{aa}:8} whenever the address @var{aa} is in the
  6263. top page of memory).
  6264. @command{ld} finds all @code{mov} instructions which use the register
  6265. indirect with 32-bit displacement addressing mode, but use a small
  6266. displacement inside 16-bit displacement range, and changes them to use
  6267. the 16-bit displacement form. (That is: the linker turns @samp{mov.b
  6268. @code{@@}@var{d}:32,ERx} into @samp{mov.b @code{@@}@var{d}:16,ERx}
  6269. whenever the displacement @var{d} is in the 16 bit signed integer
  6270. range. Only implemented in ELF-format ld).
  6271. @item bit manipulation instructions
  6272. @command{ld} finds all bit manipulation instructions like @code{band, bclr,
  6273. biand, bild, bior, bist, bixor, bld, bnot, bor, bset, bst, btst, bxor}
  6274. which use 32 bit and 16 bit absolute address form, but refer to the top
  6275. page of memory, and changes them to use the 8 bit address form.
  6276. (That is: the linker turns @samp{bset #xx:3,@code{@@}@var{aa}:32} into
  6277. @samp{bset #xx:3,@code{@@}@var{aa}:8} whenever the address @var{aa} is in
  6278. the top page of memory).
  6279. @item system control instructions
  6280. @command{ld} finds all @code{ldc.w, stc.w} instructions which use the
  6281. 32 bit absolute address form, but refer to the top page of memory, and
  6282. changes them to use 16 bit address form.
  6283. (That is: the linker turns @samp{ldc.w @code{@@}@var{aa}:32,ccr} into
  6284. @samp{ldc.w @code{@@}@var{aa}:16,ccr} whenever the address @var{aa} is in
  6285. the top page of memory).
  6286. @end table
  6287. @ifclear GENERIC
  6288. @lowersections
  6289. @end ifclear
  6290. @end ifset
  6291. @ifclear GENERIC
  6292. @ifset Renesas
  6293. @c This stuff is pointless to say unless you're especially concerned
  6294. @c with Renesas chips; don't enable it for generic case, please.
  6295. @node Renesas
  6296. @chapter @command{ld} and Other Renesas Chips
  6297. @command{ld} also supports the Renesas (formerly Hitachi) H8/300H,
  6298. H8/500, and SH chips. No special features, commands, or command-line
  6299. options are required for these chips.
  6300. @end ifset
  6301. @end ifclear
  6302. @ifset ARM
  6303. @ifclear GENERIC
  6304. @raisesections
  6305. @end ifclear
  6306. @ifset M68HC11
  6307. @ifclear GENERIC
  6308. @raisesections
  6309. @end ifclear
  6310. @node M68HC11/68HC12
  6311. @section @command{ld} and the Motorola 68HC11 and 68HC12 families
  6312. @cindex M68HC11 and 68HC12 support
  6313. @subsection Linker Relaxation
  6314. For the Motorola 68HC11, @command{ld} can perform these global
  6315. optimizations when you specify the @samp{--relax} command-line option.
  6316. @table @emph
  6317. @cindex relaxing on M68HC11
  6318. @item relaxing address modes
  6319. @command{ld} finds all @code{jsr} and @code{jmp} instructions whose
  6320. targets are within eight bits, and turns them into eight-bit
  6321. program-counter relative @code{bsr} and @code{bra} instructions,
  6322. respectively.
  6323. @command{ld} also looks at all 16-bit extended addressing modes and
  6324. transforms them in a direct addressing mode when the address is in
  6325. page 0 (between 0 and 0x0ff).
  6326. @item relaxing gcc instruction group
  6327. When @command{gcc} is called with @option{-mrelax}, it can emit group
  6328. of instructions that the linker can optimize to use a 68HC11 direct
  6329. addressing mode. These instructions consists of @code{bclr} or
  6330. @code{bset} instructions.
  6331. @end table
  6332. @subsection Trampoline Generation
  6333. @cindex trampoline generation on M68HC11
  6334. @cindex trampoline generation on M68HC12
  6335. For 68HC11 and 68HC12, @command{ld} can generate trampoline code to
  6336. call a far function using a normal @code{jsr} instruction. The linker
  6337. will also change the relocation to some far function to use the
  6338. trampoline address instead of the function address. This is typically the
  6339. case when a pointer to a function is taken. The pointer will in fact
  6340. point to the function trampoline.
  6341. @ifclear GENERIC
  6342. @lowersections
  6343. @end ifclear
  6344. @end ifset
  6345. @node ARM
  6346. @section @command{ld} and the ARM family
  6347. @cindex ARM interworking support
  6348. @kindex --support-old-code
  6349. For the ARM, @command{ld} will generate code stubs to allow functions calls
  6350. between ARM and Thumb code. These stubs only work with code that has
  6351. been compiled and assembled with the @samp{-mthumb-interwork} command
  6352. line option. If it is necessary to link with old ARM object files or
  6353. libraries, which have not been compiled with the -mthumb-interwork
  6354. option then the @samp{--support-old-code} command-line switch should be
  6355. given to the linker. This will make it generate larger stub functions
  6356. which will work with non-interworking aware ARM code. Note, however,
  6357. the linker does not support generating stubs for function calls to
  6358. non-interworking aware Thumb code.
  6359. @cindex thumb entry point
  6360. @cindex entry point, thumb
  6361. @kindex --thumb-entry=@var{entry}
  6362. The @samp{--thumb-entry} switch is a duplicate of the generic
  6363. @samp{--entry} switch, in that it sets the program's starting address.
  6364. But it also sets the bottom bit of the address, so that it can be
  6365. branched to using a BX instruction, and the program will start
  6366. executing in Thumb mode straight away.
  6367. @cindex PE import table prefixing
  6368. @kindex --use-nul-prefixed-import-tables
  6369. The @samp{--use-nul-prefixed-import-tables} switch is specifying, that
  6370. the import tables idata4 and idata5 have to be generated with a zero
  6371. element prefix for import libraries. This is the old style to generate
  6372. import tables. By default this option is turned off.
  6373. @cindex BE8
  6374. @kindex --be8
  6375. The @samp{--be8} switch instructs @command{ld} to generate BE8 format
  6376. executables. This option is only valid when linking big-endian
  6377. objects - ie ones which have been assembled with the @option{-EB}
  6378. option. The resulting image will contain big-endian data and
  6379. little-endian code.
  6380. @cindex TARGET1
  6381. @kindex --target1-rel
  6382. @kindex --target1-abs
  6383. The @samp{R_ARM_TARGET1} relocation is typically used for entries in the
  6384. @samp{.init_array} section. It is interpreted as either @samp{R_ARM_REL32}
  6385. or @samp{R_ARM_ABS32}, depending on the target. The @samp{--target1-rel}
  6386. and @samp{--target1-abs} switches override the default.
  6387. @cindex TARGET2
  6388. @kindex --target2=@var{type}
  6389. The @samp{--target2=type} switch overrides the default definition of the
  6390. @samp{R_ARM_TARGET2} relocation. Valid values for @samp{type}, their
  6391. meanings, and target defaults are as follows:
  6392. @table @samp
  6393. @item rel
  6394. @samp{R_ARM_REL32} (arm*-*-elf, arm*-*-eabi)
  6395. @item abs
  6396. @samp{R_ARM_ABS32}
  6397. @item got-rel
  6398. @samp{R_ARM_GOT_PREL} (arm*-*-linux, arm*-*-*bsd)
  6399. @end table
  6400. @cindex FIX_V4BX
  6401. @kindex --fix-v4bx
  6402. The @samp{R_ARM_V4BX} relocation (defined by the ARM AAELF
  6403. specification) enables objects compiled for the ARMv4 architecture to be
  6404. interworking-safe when linked with other objects compiled for ARMv4t, but
  6405. also allows pure ARMv4 binaries to be built from the same ARMv4 objects.
  6406. In the latter case, the switch @option{--fix-v4bx} must be passed to the
  6407. linker, which causes v4t @code{BX rM} instructions to be rewritten as
  6408. @code{MOV PC,rM}, since v4 processors do not have a @code{BX} instruction.
  6409. In the former case, the switch should not be used, and @samp{R_ARM_V4BX}
  6410. relocations are ignored.
  6411. @cindex FIX_V4BX_INTERWORKING
  6412. @kindex --fix-v4bx-interworking
  6413. Replace @code{BX rM} instructions identified by @samp{R_ARM_V4BX}
  6414. relocations with a branch to the following veneer:
  6415. @smallexample
  6416. TST rM, #1
  6417. MOVEQ PC, rM
  6418. BX Rn
  6419. @end smallexample
  6420. This allows generation of libraries/applications that work on ARMv4 cores
  6421. and are still interworking safe. Note that the above veneer clobbers the
  6422. condition flags, so may cause incorrect program behavior in rare cases.
  6423. @cindex USE_BLX
  6424. @kindex --use-blx
  6425. The @samp{--use-blx} switch enables the linker to use ARM/Thumb
  6426. BLX instructions (available on ARMv5t and above) in various
  6427. situations. Currently it is used to perform calls via the PLT from Thumb
  6428. code using BLX rather than using BX and a mode-switching stub before
  6429. each PLT entry. This should lead to such calls executing slightly faster.
  6430. @cindex VFP11_DENORM_FIX
  6431. @kindex --vfp11-denorm-fix
  6432. The @samp{--vfp11-denorm-fix} switch enables a link-time workaround for a
  6433. bug in certain VFP11 coprocessor hardware, which sometimes allows
  6434. instructions with denorm operands (which must be handled by support code)
  6435. to have those operands overwritten by subsequent instructions before
  6436. the support code can read the intended values.
  6437. The bug may be avoided in scalar mode if you allow at least one
  6438. intervening instruction between a VFP11 instruction which uses a register
  6439. and another instruction which writes to the same register, or at least two
  6440. intervening instructions if vector mode is in use. The bug only affects
  6441. full-compliance floating-point mode: you do not need this workaround if
  6442. you are using "runfast" mode. Please contact ARM for further details.
  6443. If you know you are using buggy VFP11 hardware, you can
  6444. enable this workaround by specifying the linker option
  6445. @samp{--vfp-denorm-fix=scalar} if you are using the VFP11 scalar
  6446. mode only, or @samp{--vfp-denorm-fix=vector} if you are using
  6447. vector mode (the latter also works for scalar code). The default is
  6448. @samp{--vfp-denorm-fix=none}.
  6449. If the workaround is enabled, instructions are scanned for
  6450. potentially-troublesome sequences, and a veneer is created for each
  6451. such sequence which may trigger the erratum. The veneer consists of the
  6452. first instruction of the sequence and a branch back to the subsequent
  6453. instruction. The original instruction is then replaced with a branch to
  6454. the veneer. The extra cycles required to call and return from the veneer
  6455. are sufficient to avoid the erratum in both the scalar and vector cases.
  6456. @cindex ARM1176 erratum workaround
  6457. @kindex --fix-arm1176
  6458. @kindex --no-fix-arm1176
  6459. The @samp{--fix-arm1176} switch enables a link-time workaround for an erratum
  6460. in certain ARM1176 processors. The workaround is enabled by default if you
  6461. are targeting ARM v6 (excluding ARM v6T2) or earlier. It can be disabled
  6462. unconditionally by specifying @samp{--no-fix-arm1176}.
  6463. Further information is available in the ``ARM1176JZ-S and ARM1176JZF-S
  6464. Programmer Advice Notice'' available on the ARM documentation website at:
  6465. http://infocenter.arm.com/.
  6466. @cindex STM32L4xx erratum workaround
  6467. @kindex --fix-stm32l4xx-629360
  6468. The @samp{--fix-stm32l4xx-629360} switch enables a link-time
  6469. workaround for a bug in the bus matrix / memory controller for some of
  6470. the STM32 Cortex-M4 based products (STM32L4xx). When accessing
  6471. off-chip memory via the affected bus for bus reads of 9 words or more,
  6472. the bus can generate corrupt data and/or abort. These are only
  6473. core-initiated accesses (not DMA), and might affect any access:
  6474. integer loads such as LDM, POP and floating-point loads such as VLDM,
  6475. VPOP. Stores are not affected.
  6476. The bug can be avoided by splitting memory accesses into the
  6477. necessary chunks to keep bus reads below 8 words.
  6478. The workaround is not enabled by default, this is equivalent to use
  6479. @samp{--fix-stm32l4xx-629360=none}. If you know you are using buggy
  6480. STM32L4xx hardware, you can enable the workaround by specifying the
  6481. linker option @samp{--fix-stm32l4xx-629360}, or the equivalent
  6482. @samp{--fix-stm32l4xx-629360=default}.
  6483. If the workaround is enabled, instructions are scanned for
  6484. potentially-troublesome sequences, and a veneer is created for each
  6485. such sequence which may trigger the erratum. The veneer consists in a
  6486. replacement sequence emulating the behaviour of the original one and a
  6487. branch back to the subsequent instruction. The original instruction is
  6488. then replaced with a branch to the veneer.
  6489. The workaround does not always preserve the memory access order for
  6490. the LDMDB instruction, when the instruction loads the PC.
  6491. The workaround is not able to handle problematic instructions when
  6492. they are in the middle of an IT block, since a branch is not allowed
  6493. there. In that case, the linker reports a warning and no replacement
  6494. occurs.
  6495. The workaround is not able to replace problematic instructions with a
  6496. PC-relative branch instruction if the @samp{.text} section is too
  6497. large. In that case, when the branch that replaces the original code
  6498. cannot be encoded, the linker reports a warning and no replacement
  6499. occurs.
  6500. @cindex NO_ENUM_SIZE_WARNING
  6501. @kindex --no-enum-size-warning
  6502. The @option{--no-enum-size-warning} switch prevents the linker from
  6503. warning when linking object files that specify incompatible EABI
  6504. enumeration size attributes. For example, with this switch enabled,
  6505. linking of an object file using 32-bit enumeration values with another
  6506. using enumeration values fitted into the smallest possible space will
  6507. not be diagnosed.
  6508. @cindex NO_WCHAR_SIZE_WARNING
  6509. @kindex --no-wchar-size-warning
  6510. The @option{--no-wchar-size-warning} switch prevents the linker from
  6511. warning when linking object files that specify incompatible EABI
  6512. @code{wchar_t} size attributes. For example, with this switch enabled,
  6513. linking of an object file using 32-bit @code{wchar_t} values with another
  6514. using 16-bit @code{wchar_t} values will not be diagnosed.
  6515. @cindex PIC_VENEER
  6516. @kindex --pic-veneer
  6517. The @samp{--pic-veneer} switch makes the linker use PIC sequences for
  6518. ARM/Thumb interworking veneers, even if the rest of the binary
  6519. is not PIC. This avoids problems on uClinux targets where
  6520. @samp{--emit-relocs} is used to generate relocatable binaries.
  6521. @cindex STUB_GROUP_SIZE
  6522. @kindex --stub-group-size=@var{N}
  6523. The linker will automatically generate and insert small sequences of
  6524. code into a linked ARM ELF executable whenever an attempt is made to
  6525. perform a function call to a symbol that is too far away. The
  6526. placement of these sequences of instructions - called stubs - is
  6527. controlled by the command-line option @option{--stub-group-size=N}.
  6528. The placement is important because a poor choice can create a need for
  6529. duplicate stubs, increasing the code size. The linker will try to
  6530. group stubs together in order to reduce interruptions to the flow of
  6531. code, but it needs guidance as to how big these groups should be and
  6532. where they should be placed.
  6533. The value of @samp{N}, the parameter to the
  6534. @option{--stub-group-size=} option controls where the stub groups are
  6535. placed. If it is negative then all stubs are placed after the first
  6536. branch that needs them. If it is positive then the stubs can be
  6537. placed either before or after the branches that need them. If the
  6538. value of @samp{N} is 1 (either +1 or -1) then the linker will choose
  6539. exactly where to place groups of stubs, using its built in heuristics.
  6540. A value of @samp{N} greater than 1 (or smaller than -1) tells the
  6541. linker that a single group of stubs can service at most @samp{N} bytes
  6542. from the input sections.
  6543. The default, if @option{--stub-group-size=} is not specified, is
  6544. @samp{N = +1}.
  6545. Farcalls stubs insertion is fully supported for the ARM-EABI target
  6546. only, because it relies on object files properties not present
  6547. otherwise.
  6548. @cindex Cortex-A8 erratum workaround
  6549. @kindex --fix-cortex-a8
  6550. @kindex --no-fix-cortex-a8
  6551. The @samp{--fix-cortex-a8} switch enables a link-time workaround for an erratum in certain Cortex-A8 processors. The workaround is enabled by default if you are targeting the ARM v7-A architecture profile. It can be enabled otherwise by specifying @samp{--fix-cortex-a8}, or disabled unconditionally by specifying @samp{--no-fix-cortex-a8}.
  6552. The erratum only affects Thumb-2 code. Please contact ARM for further details.
  6553. @cindex Cortex-A53 erratum 835769 workaround
  6554. @kindex --fix-cortex-a53-835769
  6555. @kindex --no-fix-cortex-a53-835769
  6556. The @samp{--fix-cortex-a53-835769} switch enables a link-time workaround for erratum 835769 present on certain early revisions of Cortex-A53 processors. The workaround is disabled by default. It can be enabled by specifying @samp{--fix-cortex-a53-835769}, or disabled unconditionally by specifying @samp{--no-fix-cortex-a53-835769}.
  6557. Please contact ARM for further details.
  6558. @kindex --merge-exidx-entries
  6559. @kindex --no-merge-exidx-entries
  6560. @cindex Merging exidx entries
  6561. The @samp{--no-merge-exidx-entries} switch disables the merging of adjacent exidx entries in debuginfo.
  6562. @kindex --long-plt
  6563. @cindex 32-bit PLT entries
  6564. The @samp{--long-plt} option enables the use of 16 byte PLT entries
  6565. which support up to 4Gb of code. The default is to use 12 byte PLT
  6566. entries which only support 512Mb of code.
  6567. @kindex --no-apply-dynamic-relocs
  6568. @cindex AArch64 rela addend
  6569. The @samp{--no-apply-dynamic-relocs} option makes AArch64 linker do not apply
  6570. link-time values for dynamic relocations.
  6571. @cindex Placement of SG veneers
  6572. All SG veneers are placed in the special output section @code{.gnu.sgstubs}.
  6573. Its start address must be set, either with the command-line option
  6574. @samp{--section-start} or in a linker script, to indicate where to place these
  6575. veneers in memory.
  6576. @kindex --cmse-implib
  6577. @cindex Secure gateway import library
  6578. The @samp{--cmse-implib} option requests that the import libraries
  6579. specified by the @samp{--out-implib} and @samp{--in-implib} options are
  6580. secure gateway import libraries, suitable for linking a non-secure
  6581. executable against secure code as per ARMv8-M Security Extensions.
  6582. @kindex --in-implib=@var{file}
  6583. @cindex Input import library
  6584. The @samp{--in-implib=file} specifies an input import library whose symbols
  6585. must keep the same address in the executable being produced. A warning is
  6586. given if no @samp{--out-implib} is given but new symbols have been introduced
  6587. in the executable that should be listed in its import library. Otherwise, if
  6588. @samp{--out-implib} is specified, the symbols are added to the output import
  6589. library. A warning is also given if some symbols present in the input import
  6590. library have disappeared from the executable. This option is only effective
  6591. for Secure Gateway import libraries, ie. when @samp{--cmse-implib} is
  6592. specified.
  6593. @ifclear GENERIC
  6594. @lowersections
  6595. @end ifclear
  6596. @end ifset
  6597. @ifset HPPA
  6598. @ifclear GENERIC
  6599. @raisesections
  6600. @end ifclear
  6601. @node HPPA ELF32
  6602. @section @command{ld} and HPPA 32-bit ELF Support
  6603. @cindex HPPA multiple sub-space stubs
  6604. @kindex --multi-subspace
  6605. When generating a shared library, @command{ld} will by default generate
  6606. import stubs suitable for use with a single sub-space application.
  6607. The @samp{--multi-subspace} switch causes @command{ld} to generate export
  6608. stubs, and different (larger) import stubs suitable for use with
  6609. multiple sub-spaces.
  6610. @cindex HPPA stub grouping
  6611. @kindex --stub-group-size=@var{N}
  6612. Long branch stubs and import/export stubs are placed by @command{ld} in
  6613. stub sections located between groups of input sections.
  6614. @samp{--stub-group-size} specifies the maximum size of a group of input
  6615. sections handled by one stub section. Since branch offsets are signed,
  6616. a stub section may serve two groups of input sections, one group before
  6617. the stub section, and one group after it. However, when using
  6618. conditional branches that require stubs, it may be better (for branch
  6619. prediction) that stub sections only serve one group of input sections.
  6620. A negative value for @samp{N} chooses this scheme, ensuring that
  6621. branches to stubs always use a negative offset. Two special values of
  6622. @samp{N} are recognized, @samp{1} and @samp{-1}. These both instruct
  6623. @command{ld} to automatically size input section groups for the branch types
  6624. detected, with the same behaviour regarding stub placement as other
  6625. positive or negative values of @samp{N} respectively.
  6626. Note that @samp{--stub-group-size} does not split input sections. A
  6627. single input section larger than the group size specified will of course
  6628. create a larger group (of one section). If input sections are too
  6629. large, it may not be possible for a branch to reach its stub.
  6630. @ifclear GENERIC
  6631. @lowersections
  6632. @end ifclear
  6633. @end ifset
  6634. @ifset M68K
  6635. @ifclear GENERIC
  6636. @raisesections
  6637. @end ifclear
  6638. @node M68K
  6639. @section @command{ld} and the Motorola 68K family
  6640. @cindex Motorola 68K GOT generation
  6641. @kindex --got=@var{type}
  6642. The @samp{--got=@var{type}} option lets you choose the GOT generation scheme.
  6643. The choices are @samp{single}, @samp{negative}, @samp{multigot} and
  6644. @samp{target}. When @samp{target} is selected the linker chooses
  6645. the default GOT generation scheme for the current target.
  6646. @samp{single} tells the linker to generate a single GOT with
  6647. entries only at non-negative offsets.
  6648. @samp{negative} instructs the linker to generate a single GOT with
  6649. entries at both negative and positive offsets. Not all environments
  6650. support such GOTs.
  6651. @samp{multigot} allows the linker to generate several GOTs in the
  6652. output file. All GOT references from a single input object
  6653. file access the same GOT, but references from different input object
  6654. files might access different GOTs. Not all environments support such GOTs.
  6655. @ifclear GENERIC
  6656. @lowersections
  6657. @end ifclear
  6658. @end ifset
  6659. @ifset MIPS
  6660. @ifclear GENERIC
  6661. @raisesections
  6662. @end ifclear
  6663. @node MIPS
  6664. @section @command{ld} and the MIPS family
  6665. @cindex MIPS microMIPS instruction choice selection
  6666. @kindex --insn32
  6667. @kindex --no-insn32
  6668. The @samp{--insn32} and @samp{--no-insn32} options control the choice of
  6669. microMIPS instructions used in code generated by the linker, such as that
  6670. in the PLT or lazy binding stubs, or in relaxation. If @samp{--insn32} is
  6671. used, then the linker only uses 32-bit instruction encodings. By default
  6672. or if @samp{--no-insn32} is used, all instruction encodings are used,
  6673. including 16-bit ones where possible.
  6674. @cindex MIPS branch relocation check control
  6675. @kindex --ignore-branch-isa
  6676. @kindex --no-ignore-branch-isa
  6677. The @samp{--ignore-branch-isa} and @samp{--no-ignore-branch-isa} options
  6678. control branch relocation checks for invalid ISA mode transitions. If
  6679. @samp{--ignore-branch-isa} is used, then the linker accepts any branch
  6680. relocations and any ISA mode transition required is lost in relocation
  6681. calculation, except for some cases of @code{BAL} instructions which meet
  6682. relaxation conditions and are converted to equivalent @code{JALX}
  6683. instructions as the associated relocation is calculated. By default
  6684. or if @samp{--no-ignore-branch-isa} is used a check is made causing
  6685. the loss of an ISA mode transition to produce an error.
  6686. @ifclear GENERIC
  6687. @lowersections
  6688. @end ifclear
  6689. @end ifset
  6690. @ifset MMIX
  6691. @ifclear GENERIC
  6692. @raisesections
  6693. @end ifclear
  6694. @node MMIX
  6695. @section @code{ld} and MMIX
  6696. For MMIX, there is a choice of generating @code{ELF} object files or
  6697. @code{mmo} object files when linking. The simulator @code{mmix}
  6698. understands the @code{mmo} format. The binutils @code{objcopy} utility
  6699. can translate between the two formats.
  6700. There is one special section, the @samp{.MMIX.reg_contents} section.
  6701. Contents in this section is assumed to correspond to that of global
  6702. registers, and symbols referring to it are translated to special symbols,
  6703. equal to registers. In a final link, the start address of the
  6704. @samp{.MMIX.reg_contents} section corresponds to the first allocated
  6705. global register multiplied by 8. Register @code{$255} is not included in
  6706. this section; it is always set to the program entry, which is at the
  6707. symbol @code{Main} for @code{mmo} files.
  6708. Global symbols with the prefix @code{__.MMIX.start.}, for example
  6709. @code{__.MMIX.start..text} and @code{__.MMIX.start..data} are special.
  6710. The default linker script uses these to set the default start address
  6711. of a section.
  6712. Initial and trailing multiples of zero-valued 32-bit words in a section,
  6713. are left out from an mmo file.
  6714. @ifclear GENERIC
  6715. @lowersections
  6716. @end ifclear
  6717. @end ifset
  6718. @ifset MSP430
  6719. @ifclear GENERIC
  6720. @raisesections
  6721. @end ifclear
  6722. @node MSP430
  6723. @section @code{ld} and MSP430
  6724. For the MSP430 it is possible to select the MPU architecture. The flag @samp{-m [mpu type]}
  6725. will select an appropriate linker script for selected MPU type. (To get a list of known MPUs
  6726. just pass @samp{-m help} option to the linker).
  6727. @cindex MSP430 extra sections
  6728. The linker will recognize some extra sections which are MSP430 specific:
  6729. @table @code
  6730. @item @samp{.vectors}
  6731. Defines a portion of ROM where interrupt vectors located.
  6732. @item @samp{.bootloader}
  6733. Defines the bootloader portion of the ROM (if applicable). Any code
  6734. in this section will be uploaded to the MPU.
  6735. @item @samp{.infomem}
  6736. Defines an information memory section (if applicable). Any code in
  6737. this section will be uploaded to the MPU.
  6738. @item @samp{.infomemnobits}
  6739. This is the same as the @samp{.infomem} section except that any code
  6740. in this section will not be uploaded to the MPU.
  6741. @item @samp{.noinit}
  6742. Denotes a portion of RAM located above @samp{.bss} section.
  6743. The last two sections are used by gcc.
  6744. @end table
  6745. @table @option
  6746. @cindex MSP430 Options
  6747. @kindex --code-region
  6748. @item --code-region=[either,lower,upper,none]
  6749. This will transform .text* sections to [either,lower,upper].text* sections. The
  6750. argument passed to GCC for -mcode-region is propagated to the linker
  6751. using this option.
  6752. @kindex --data-region
  6753. @item --data-region=[either,lower,upper,none]
  6754. This will transform .data*, .bss* and .rodata* sections to
  6755. [either,lower,upper].[data,bss,rodata]* sections. The argument passed to GCC
  6756. for -mdata-region is propagated to the linker using this option.
  6757. @kindex --disable-sec-transformation
  6758. @item --disable-sec-transformation
  6759. Prevent the transformation of sections as specified by the @code{--code-region}
  6760. and @code{--data-region} options.
  6761. This is useful if you are compiling and linking using a single call to the GCC
  6762. wrapper, and want to compile the source files using -m[code,data]-region but
  6763. not transform the sections for prebuilt libraries and objects.
  6764. @end table
  6765. @ifclear GENERIC
  6766. @lowersections
  6767. @end ifclear
  6768. @end ifset
  6769. @ifset NDS32
  6770. @ifclear GENERIC
  6771. @raisesections
  6772. @end ifclear
  6773. @node NDS32
  6774. @section @code{ld} and NDS32
  6775. @kindex relaxing on NDS32
  6776. For NDS32, there are some options to select relaxation behavior. The linker
  6777. relaxes objects according to these options.
  6778. @table @code
  6779. @item @samp{--m[no-]fp-as-gp}
  6780. Disable/enable fp-as-gp relaxation.
  6781. @item @samp{--mexport-symbols=FILE}
  6782. Exporting symbols and their address into FILE as linker script.
  6783. @item @samp{--m[no-]ex9}
  6784. Disable/enable link-time EX9 relaxation.
  6785. @item @samp{--mexport-ex9=FILE}
  6786. Export the EX9 table after linking.
  6787. @item @samp{--mimport-ex9=FILE}
  6788. Import the Ex9 table for EX9 relaxation.
  6789. @item @samp{--mupdate-ex9}
  6790. Update the existing EX9 table.
  6791. @item @samp{--mex9-limit=NUM}
  6792. Maximum number of entries in the ex9 table.
  6793. @item @samp{--mex9-loop-aware}
  6794. Avoid generating the EX9 instruction inside the loop.
  6795. @item @samp{--m[no-]ifc}
  6796. Disable/enable the link-time IFC optimization.
  6797. @item @samp{--mifc-loop-aware}
  6798. Avoid generating the IFC instruction inside the loop.
  6799. @end table
  6800. @ifclear GENERIC
  6801. @lowersections
  6802. @end ifclear
  6803. @end ifset
  6804. @ifset NIOSII
  6805. @ifclear GENERIC
  6806. @raisesections
  6807. @end ifclear
  6808. @node Nios II
  6809. @section @command{ld} and the Altera Nios II
  6810. @cindex Nios II call relaxation
  6811. @kindex --relax on Nios II
  6812. Call and immediate jump instructions on Nios II processors are limited to
  6813. transferring control to addresses in the same 256MB memory segment,
  6814. which may result in @command{ld} giving
  6815. @samp{relocation truncated to fit} errors with very large programs.
  6816. The command-line option @option{--relax} enables the generation of
  6817. trampolines that can access the entire 32-bit address space for calls
  6818. outside the normal @code{call} and @code{jmpi} address range. These
  6819. trampolines are inserted at section boundaries, so may not themselves
  6820. be reachable if an input section and its associated call trampolines are
  6821. larger than 256MB.
  6822. The @option{--relax} option is enabled by default unless @option{-r}
  6823. is also specified. You can disable trampoline generation by using the
  6824. @option{--no-relax} linker option. You can also disable this optimization
  6825. locally by using the @samp{set .noat} directive in assembly-language
  6826. source files, as the linker-inserted trampolines use the @code{at}
  6827. register as a temporary.
  6828. Note that the linker @option{--relax} option is independent of assembler
  6829. relaxation options, and that using the GNU assembler's @option{-relax-all}
  6830. option interferes with the linker's more selective call instruction relaxation.
  6831. @ifclear GENERIC
  6832. @lowersections
  6833. @end ifclear
  6834. @end ifset
  6835. @ifset POWERPC
  6836. @ifclear GENERIC
  6837. @raisesections
  6838. @end ifclear
  6839. @node PowerPC ELF32
  6840. @section @command{ld} and PowerPC 32-bit ELF Support
  6841. @cindex PowerPC long branches
  6842. @kindex --relax on PowerPC
  6843. Branches on PowerPC processors are limited to a signed 26-bit
  6844. displacement, which may result in @command{ld} giving
  6845. @samp{relocation truncated to fit} errors with very large programs.
  6846. @samp{--relax} enables the generation of trampolines that can access
  6847. the entire 32-bit address space. These trampolines are inserted at
  6848. section boundaries, so may not themselves be reachable if an input
  6849. section exceeds 33M in size. You may combine @samp{-r} and
  6850. @samp{--relax} to add trampolines in a partial link. In that case
  6851. both branches to undefined symbols and inter-section branches are also
  6852. considered potentially out of range, and trampolines inserted.
  6853. @cindex PowerPC ELF32 options
  6854. @table @option
  6855. @cindex PowerPC PLT
  6856. @kindex --bss-plt
  6857. @item --bss-plt
  6858. Current PowerPC GCC accepts a @samp{-msecure-plt} option that
  6859. generates code capable of using a newer PLT and GOT layout that has
  6860. the security advantage of no executable section ever needing to be
  6861. writable and no writable section ever being executable. PowerPC
  6862. @command{ld} will generate this layout, including stubs to access the
  6863. PLT, if all input files (including startup and static libraries) were
  6864. compiled with @samp{-msecure-plt}. @samp{--bss-plt} forces the old
  6865. BSS PLT (and GOT layout) which can give slightly better performance.
  6866. @kindex --secure-plt
  6867. @item --secure-plt
  6868. @command{ld} will use the new PLT and GOT layout if it is linking new
  6869. @samp{-fpic} or @samp{-fPIC} code, but does not do so automatically
  6870. when linking non-PIC code. This option requests the new PLT and GOT
  6871. layout. A warning will be given if some object file requires the old
  6872. style BSS PLT.
  6873. @cindex PowerPC GOT
  6874. @kindex --sdata-got
  6875. @item --sdata-got
  6876. The new secure PLT and GOT are placed differently relative to other
  6877. sections compared to older BSS PLT and GOT placement. The location of
  6878. @code{.plt} must change because the new secure PLT is an initialized
  6879. section while the old PLT is uninitialized. The reason for the
  6880. @code{.got} change is more subtle: The new placement allows
  6881. @code{.got} to be read-only in applications linked with
  6882. @samp{-z relro -z now}. However, this placement means that
  6883. @code{.sdata} cannot always be used in shared libraries, because the
  6884. PowerPC ABI accesses @code{.sdata} in shared libraries from the GOT
  6885. pointer. @samp{--sdata-got} forces the old GOT placement. PowerPC
  6886. GCC doesn't use @code{.sdata} in shared libraries, so this option is
  6887. really only useful for other compilers that may do so.
  6888. @cindex PowerPC stub symbols
  6889. @kindex --emit-stub-syms
  6890. @item --emit-stub-syms
  6891. This option causes @command{ld} to label linker stubs with a local
  6892. symbol that encodes the stub type and destination.
  6893. @cindex PowerPC TLS optimization
  6894. @kindex --no-tls-optimize
  6895. @item --no-tls-optimize
  6896. PowerPC @command{ld} normally performs some optimization of code
  6897. sequences used to access Thread-Local Storage. Use this option to
  6898. disable the optimization.
  6899. @end table
  6900. @ifclear GENERIC
  6901. @lowersections
  6902. @end ifclear
  6903. @end ifset
  6904. @ifset POWERPC64
  6905. @ifclear GENERIC
  6906. @raisesections
  6907. @end ifclear
  6908. @node PowerPC64 ELF64
  6909. @section @command{ld} and PowerPC64 64-bit ELF Support
  6910. @cindex PowerPC64 ELF64 options
  6911. @table @option
  6912. @cindex PowerPC64 stub grouping
  6913. @kindex --stub-group-size
  6914. @item --stub-group-size
  6915. Long branch stubs, PLT call stubs and TOC adjusting stubs are placed
  6916. by @command{ld} in stub sections located between groups of input sections.
  6917. @samp{--stub-group-size} specifies the maximum size of a group of input
  6918. sections handled by one stub section. Since branch offsets are signed,
  6919. a stub section may serve two groups of input sections, one group before
  6920. the stub section, and one group after it. However, when using
  6921. conditional branches that require stubs, it may be better (for branch
  6922. prediction) that stub sections only serve one group of input sections.
  6923. A negative value for @samp{N} chooses this scheme, ensuring that
  6924. branches to stubs always use a negative offset. Two special values of
  6925. @samp{N} are recognized, @samp{1} and @samp{-1}. These both instruct
  6926. @command{ld} to automatically size input section groups for the branch types
  6927. detected, with the same behaviour regarding stub placement as other
  6928. positive or negative values of @samp{N} respectively.
  6929. Note that @samp{--stub-group-size} does not split input sections. A
  6930. single input section larger than the group size specified will of course
  6931. create a larger group (of one section). If input sections are too
  6932. large, it may not be possible for a branch to reach its stub.
  6933. @cindex PowerPC64 stub symbols
  6934. @kindex --emit-stub-syms
  6935. @item --emit-stub-syms
  6936. This option causes @command{ld} to label linker stubs with a local
  6937. symbol that encodes the stub type and destination.
  6938. @cindex PowerPC64 dot symbols
  6939. @kindex --dotsyms
  6940. @kindex --no-dotsyms
  6941. @item --dotsyms
  6942. @itemx --no-dotsyms
  6943. These two options control how @command{ld} interprets version patterns
  6944. in a version script. Older PowerPC64 compilers emitted both a
  6945. function descriptor symbol with the same name as the function, and a
  6946. code entry symbol with the name prefixed by a dot (@samp{.}). To
  6947. properly version a function @samp{foo}, the version script thus needs
  6948. to control both @samp{foo} and @samp{.foo}. The option
  6949. @samp{--dotsyms}, on by default, automatically adds the required
  6950. dot-prefixed patterns. Use @samp{--no-dotsyms} to disable this
  6951. feature.
  6952. @cindex PowerPC64 register save/restore functions
  6953. @kindex --save-restore-funcs
  6954. @kindex --no-save-restore-funcs
  6955. @item --save-restore-funcs
  6956. @itemx --no-save-restore-funcs
  6957. These two options control whether PowerPC64 @command{ld} automatically
  6958. provides out-of-line register save and restore functions used by
  6959. @samp{-Os} code. The default is to provide any such referenced
  6960. function for a normal final link, and to not do so for a relocatable
  6961. link.
  6962. @cindex PowerPC64 TLS optimization
  6963. @kindex --no-tls-optimize
  6964. @item --no-tls-optimize
  6965. PowerPC64 @command{ld} normally performs some optimization of code
  6966. sequences used to access Thread-Local Storage. Use this option to
  6967. disable the optimization.
  6968. @cindex PowerPC64 __tls_get_addr optimization
  6969. @kindex --tls-get-addr-optimize
  6970. @kindex --no-tls-get-addr-optimize
  6971. @kindex --tls-get-addr-regsave
  6972. @kindex --no-tls-get-addr-regsave
  6973. @item --tls-get-addr-optimize
  6974. @itemx --no-tls-get-addr-optimize
  6975. These options control how PowerPC64 @command{ld} uses a special
  6976. stub to call __tls_get_addr. PowerPC64 glibc 2.22 and later support
  6977. an optimization that allows the second and subsequent calls to
  6978. @code{__tls_get_addr} for a given symbol to be resolved by the special
  6979. stub without calling in to glibc. By default the linker enables
  6980. generation of the stub when glibc advertises the availability of
  6981. __tls_get_addr_opt.
  6982. Using @option{--tls-get-addr-optimize} with an older glibc won't do
  6983. much besides slow down your applications, but may be useful if linking
  6984. an application against an older glibc with the expectation that it
  6985. will normally be used on systems having a newer glibc.
  6986. @option{--tls-get-addr-regsave} forces generation of a stub that saves
  6987. and restores volatile registers around the call into glibc. Normally,
  6988. this is done when the linker detects a call to __tls_get_addr_desc.
  6989. Such calls then go via the register saving stub to __tls_get_addr_opt.
  6990. @option{--no-tls-get-addr-regsave} disables generation of the
  6991. register saves.
  6992. @cindex PowerPC64 OPD optimization
  6993. @kindex --no-opd-optimize
  6994. @item --no-opd-optimize
  6995. PowerPC64 @command{ld} normally removes @code{.opd} section entries
  6996. corresponding to deleted link-once functions, or functions removed by
  6997. the action of @samp{--gc-sections} or linker script @code{/DISCARD/}.
  6998. Use this option to disable @code{.opd} optimization.
  6999. @cindex PowerPC64 OPD spacing
  7000. @kindex --non-overlapping-opd
  7001. @item --non-overlapping-opd
  7002. Some PowerPC64 compilers have an option to generate compressed
  7003. @code{.opd} entries spaced 16 bytes apart, overlapping the third word,
  7004. the static chain pointer (unused in C) with the first word of the next
  7005. entry. This option expands such entries to the full 24 bytes.
  7006. @cindex PowerPC64 TOC optimization
  7007. @kindex --no-toc-optimize
  7008. @item --no-toc-optimize
  7009. PowerPC64 @command{ld} normally removes unused @code{.toc} section
  7010. entries. Such entries are detected by examining relocations that
  7011. reference the TOC in code sections. A reloc in a deleted code section
  7012. marks a TOC word as unneeded, while a reloc in a kept code section
  7013. marks a TOC word as needed. Since the TOC may reference itself, TOC
  7014. relocs are also examined. TOC words marked as both needed and
  7015. unneeded will of course be kept. TOC words without any referencing
  7016. reloc are assumed to be part of a multi-word entry, and are kept or
  7017. discarded as per the nearest marked preceding word. This works
  7018. reliably for compiler generated code, but may be incorrect if assembly
  7019. code is used to insert TOC entries. Use this option to disable the
  7020. optimization.
  7021. @cindex PowerPC64 inline PLT call optimization
  7022. @kindex --no-inline-optimize
  7023. @item --no-inline-optimize
  7024. PowerPC64 @command{ld} normally replaces inline PLT call sequences
  7025. marked with @code{R_PPC64_PLTSEQ}, @code{R_PPC64_PLTCALL},
  7026. @code{R_PPC64_PLT16_HA} and @code{R_PPC64_PLT16_LO_DS} relocations by
  7027. a number of @code{nop}s and a direct call when the function is defined
  7028. locally and can't be overridden by some other definition. This option
  7029. disables that optimization.
  7030. @cindex PowerPC64 multi-TOC
  7031. @kindex --no-multi-toc
  7032. @item --no-multi-toc
  7033. If given any toc option besides @code{-mcmodel=medium} or
  7034. @code{-mcmodel=large}, PowerPC64 GCC generates code for a TOC model
  7035. where TOC
  7036. entries are accessed with a 16-bit offset from r2. This limits the
  7037. total TOC size to 64K. PowerPC64 @command{ld} extends this limit by
  7038. grouping code sections such that each group uses less than 64K for its
  7039. TOC entries, then inserts r2 adjusting stubs between inter-group
  7040. calls. @command{ld} does not split apart input sections, so cannot
  7041. help if a single input file has a @code{.toc} section that exceeds
  7042. 64K, most likely from linking multiple files with @command{ld -r}.
  7043. Use this option to turn off this feature.
  7044. @cindex PowerPC64 TOC sorting
  7045. @kindex --no-toc-sort
  7046. @item --no-toc-sort
  7047. By default, @command{ld} sorts TOC sections so that those whose file
  7048. happens to have a section called @code{.init} or @code{.fini} are
  7049. placed first, followed by TOC sections referenced by code generated
  7050. with PowerPC64 gcc's @code{-mcmodel=small}, and lastly TOC sections
  7051. referenced only by code generated with PowerPC64 gcc's
  7052. @code{-mcmodel=medium} or @code{-mcmodel=large} options. Doing this
  7053. results in better TOC grouping for multi-TOC. Use this option to turn
  7054. off this feature.
  7055. @cindex PowerPC64 PLT stub alignment
  7056. @kindex --plt-align
  7057. @kindex --no-plt-align
  7058. @item --plt-align
  7059. @itemx --no-plt-align
  7060. Use these options to control whether individual PLT call stubs are
  7061. aligned to a 32-byte boundary, or to the specified power of two
  7062. boundary when using @code{--plt-align=}. A negative value may be
  7063. specified to pad PLT call stubs so that they do not cross the
  7064. specified power of two boundary (or the minimum number of boundaries
  7065. if a PLT stub is so large that it must cross a boundary). By default
  7066. PLT call stubs are aligned to 32-byte boundaries.
  7067. @cindex PowerPC64 PLT call stub static chain
  7068. @kindex --plt-static-chain
  7069. @kindex --no-plt-static-chain
  7070. @item --plt-static-chain
  7071. @itemx --no-plt-static-chain
  7072. Use these options to control whether PLT call stubs load the static
  7073. chain pointer (r11). @code{ld} defaults to not loading the static
  7074. chain since there is never any need to do so on a PLT call.
  7075. @cindex PowerPC64 PLT call stub thread safety
  7076. @kindex --plt-thread-safe
  7077. @kindex --no-plt-thread-safe
  7078. @item --plt-thread-safe
  7079. @itemx --no-plt-thread-safe
  7080. With power7's weakly ordered memory model, it is possible when using
  7081. lazy binding for ld.so to update a plt entry in one thread and have
  7082. another thread see the individual plt entry words update in the wrong
  7083. order, despite ld.so carefully writing in the correct order and using
  7084. memory write barriers. To avoid this we need some sort of read
  7085. barrier in the call stub, or use LD_BIND_NOW=1. By default, @code{ld}
  7086. looks for calls to commonly used functions that create threads, and if
  7087. seen, adds the necessary barriers. Use these options to change the
  7088. default behaviour.
  7089. @cindex PowerPC64 ELFv2 PLT localentry optimization
  7090. @kindex --plt-localentry
  7091. @kindex --no-plt-localentry
  7092. @item --plt-localentry
  7093. @itemx --no-localentry
  7094. ELFv2 functions with localentry:0 are those with a single entry point,
  7095. ie. global entry == local entry, and that have no requirement on r2
  7096. (the TOC/GOT pointer) or r12, and guarantee r2 is unchanged on return.
  7097. Such an external function can be called via the PLT without saving r2
  7098. or restoring it on return, avoiding a common load-hit-store for small
  7099. functions. The optimization is attractive, with up to 40% reduction
  7100. in execution time for a small function, but can result in symbol
  7101. interposition failures. Also, minor changes in a shared library,
  7102. including system libraries, can cause a function that was localentry:0
  7103. to become localentry:8. This will result in a dynamic loader
  7104. complaint and failure to run. The option is experimental, use with
  7105. care. @option{--no-plt-localentry} is the default.
  7106. @cindex PowerPC64 Power10 stubs
  7107. @kindex --power10-stubs
  7108. @kindex --no-power10-stubs
  7109. @item --power10-stubs
  7110. @itemx --no-power10-stubs
  7111. When PowerPC64 @command{ld} links input object files containing
  7112. relocations used on power10 prefixed instructions it normally creates
  7113. linkage stubs (PLT call and long branch) using power10 instructions
  7114. for @code{@@notoc} PLT calls where @code{r2} is not known. The
  7115. power10 notoc stubs are smaller and faster, so are preferred for
  7116. power10. @option{--power10-stubs} and @option{--no-power10-stubs}
  7117. allow you to override the linker's selection of stub instructions.
  7118. @option{--power10-stubs=auto} allows the user to select the default
  7119. auto mode.
  7120. @end table
  7121. @ifclear GENERIC
  7122. @lowersections
  7123. @end ifclear
  7124. @end ifset
  7125. @ifset S/390
  7126. @ifclear GENERIC
  7127. @raisesections
  7128. @end ifclear
  7129. @node S/390 ELF
  7130. @section @command{ld} and S/390 ELF Support
  7131. @cindex S/390 ELF options
  7132. @table @option
  7133. @cindex S/390
  7134. @kindex --s390-pgste
  7135. @item --s390-pgste
  7136. This option marks the result file with a @code{PT_S390_PGSTE}
  7137. segment. The Linux kernel is supposed to allocate 4k page tables for
  7138. binaries marked that way.
  7139. @end table
  7140. @ifclear GENERIC
  7141. @lowersections
  7142. @end ifclear
  7143. @end ifset
  7144. @ifset SPU
  7145. @ifclear GENERIC
  7146. @raisesections
  7147. @end ifclear
  7148. @node SPU ELF
  7149. @section @command{ld} and SPU ELF Support
  7150. @cindex SPU ELF options
  7151. @table @option
  7152. @cindex SPU plugins
  7153. @kindex --plugin
  7154. @item --plugin
  7155. This option marks an executable as a PIC plugin module.
  7156. @cindex SPU overlays
  7157. @kindex --no-overlays
  7158. @item --no-overlays
  7159. Normally, @command{ld} recognizes calls to functions within overlay
  7160. regions, and redirects such calls to an overlay manager via a stub.
  7161. @command{ld} also provides a built-in overlay manager. This option
  7162. turns off all this special overlay handling.
  7163. @cindex SPU overlay stub symbols
  7164. @kindex --emit-stub-syms
  7165. @item --emit-stub-syms
  7166. This option causes @command{ld} to label overlay stubs with a local
  7167. symbol that encodes the stub type and destination.
  7168. @cindex SPU extra overlay stubs
  7169. @kindex --extra-overlay-stubs
  7170. @item --extra-overlay-stubs
  7171. This option causes @command{ld} to add overlay call stubs on all
  7172. function calls out of overlay regions. Normally stubs are not added
  7173. on calls to non-overlay regions.
  7174. @cindex SPU local store size
  7175. @kindex --local-store=lo:hi
  7176. @item --local-store=lo:hi
  7177. @command{ld} usually checks that a final executable for SPU fits in
  7178. the address range 0 to 256k. This option may be used to change the
  7179. range. Disable the check entirely with @option{--local-store=0:0}.
  7180. @cindex SPU
  7181. @kindex --stack-analysis
  7182. @item --stack-analysis
  7183. SPU local store space is limited. Over-allocation of stack space
  7184. unnecessarily limits space available for code and data, while
  7185. under-allocation results in runtime failures. If given this option,
  7186. @command{ld} will provide an estimate of maximum stack usage.
  7187. @command{ld} does this by examining symbols in code sections to
  7188. determine the extents of functions, and looking at function prologues
  7189. for stack adjusting instructions. A call-graph is created by looking
  7190. for relocations on branch instructions. The graph is then searched
  7191. for the maximum stack usage path. Note that this analysis does not
  7192. find calls made via function pointers, and does not handle recursion
  7193. and other cycles in the call graph. Stack usage may be
  7194. under-estimated if your code makes such calls. Also, stack usage for
  7195. dynamic allocation, e.g. alloca, will not be detected. If a link map
  7196. is requested, detailed information about each function's stack usage
  7197. and calls will be given.
  7198. @cindex SPU
  7199. @kindex --emit-stack-syms
  7200. @item --emit-stack-syms
  7201. This option, if given along with @option{--stack-analysis} will result
  7202. in @command{ld} emitting stack sizing symbols for each function.
  7203. These take the form @code{__stack_<function_name>} for global
  7204. functions, and @code{__stack_<number>_<function_name>} for static
  7205. functions. @code{<number>} is the section id in hex. The value of
  7206. such symbols is the stack requirement for the corresponding function.
  7207. The symbol size will be zero, type @code{STT_NOTYPE}, binding
  7208. @code{STB_LOCAL}, and section @code{SHN_ABS}.
  7209. @end table
  7210. @ifclear GENERIC
  7211. @lowersections
  7212. @end ifclear
  7213. @end ifset
  7214. @ifset TICOFF
  7215. @ifclear GENERIC
  7216. @raisesections
  7217. @end ifclear
  7218. @node TI COFF
  7219. @section @command{ld}'s Support for Various TI COFF Versions
  7220. @cindex TI COFF versions
  7221. @kindex --format=@var{version}
  7222. The @samp{--format} switch allows selection of one of the various
  7223. TI COFF versions. The latest of this writing is 2; versions 0 and 1 are
  7224. also supported. The TI COFF versions also vary in header byte-order
  7225. format; @command{ld} will read any version or byte order, but the output
  7226. header format depends on the default specified by the specific target.
  7227. @ifclear GENERIC
  7228. @lowersections
  7229. @end ifclear
  7230. @end ifset
  7231. @ifset WIN32
  7232. @ifclear GENERIC
  7233. @raisesections
  7234. @end ifclear
  7235. @node WIN32
  7236. @section @command{ld} and WIN32 (cygwin/mingw)
  7237. This section describes some of the win32 specific @command{ld} issues.
  7238. See @ref{Options,,Command-line Options} for detailed description of the
  7239. command-line options mentioned here.
  7240. @table @emph
  7241. @cindex import libraries
  7242. @item import libraries
  7243. The standard Windows linker creates and uses so-called import
  7244. libraries, which contains information for linking to dll's. They are
  7245. regular static archives and are handled as any other static
  7246. archive. The cygwin and mingw ports of @command{ld} have specific
  7247. support for creating such libraries provided with the
  7248. @samp{--out-implib} command-line option.
  7249. @item exporting DLL symbols
  7250. @cindex exporting DLL symbols
  7251. The cygwin/mingw @command{ld} has several ways to export symbols for dll's.
  7252. @table @emph
  7253. @item using auto-export functionality
  7254. @cindex using auto-export functionality
  7255. By default @command{ld} exports symbols with the auto-export functionality,
  7256. which is controlled by the following command-line options:
  7257. @itemize
  7258. @item --export-all-symbols [This is the default]
  7259. @item --exclude-symbols
  7260. @item --exclude-libs
  7261. @item --exclude-modules-for-implib
  7262. @item --version-script
  7263. @end itemize
  7264. When auto-export is in operation, @command{ld} will export all the non-local
  7265. (global and common) symbols it finds in a DLL, with the exception of a few
  7266. symbols known to belong to the system's runtime and libraries. As it will
  7267. often not be desirable to export all of a DLL's symbols, which may include
  7268. private functions that are not part of any public interface, the command-line
  7269. options listed above may be used to filter symbols out from the list for
  7270. exporting. The @samp{--output-def} option can be used in order to see the
  7271. final list of exported symbols with all exclusions taken into effect.
  7272. If @samp{--export-all-symbols} is not given explicitly on the
  7273. command line, then the default auto-export behavior will be @emph{disabled}
  7274. if either of the following are true:
  7275. @itemize
  7276. @item A DEF file is used.
  7277. @item Any symbol in any object file was marked with the __declspec(dllexport) attribute.
  7278. @end itemize
  7279. @item using a DEF file
  7280. @cindex using a DEF file
  7281. Another way of exporting symbols is using a DEF file. A DEF file is
  7282. an ASCII file containing definitions of symbols which should be
  7283. exported when a dll is created. Usually it is named @samp{<dll
  7284. name>.def} and is added as any other object file to the linker's
  7285. command line. The file's name must end in @samp{.def} or @samp{.DEF}.
  7286. @example
  7287. gcc -o <output> <objectfiles> <dll name>.def
  7288. @end example
  7289. Using a DEF file turns off the normal auto-export behavior, unless the
  7290. @samp{--export-all-symbols} option is also used.
  7291. Here is an example of a DEF file for a shared library called @samp{xyz.dll}:
  7292. @example
  7293. LIBRARY "xyz.dll" BASE=0x20000000
  7294. EXPORTS
  7295. foo
  7296. bar
  7297. _bar = bar
  7298. another_foo = abc.dll.afoo
  7299. var1 DATA
  7300. doo = foo == foo2
  7301. eoo DATA == var1
  7302. @end example
  7303. This example defines a DLL with a non-default base address and seven
  7304. symbols in the export table. The third exported symbol @code{_bar} is an
  7305. alias for the second. The fourth symbol, @code{another_foo} is resolved
  7306. by "forwarding" to another module and treating it as an alias for
  7307. @code{afoo} exported from the DLL @samp{abc.dll}. The final symbol
  7308. @code{var1} is declared to be a data object. The @samp{doo} symbol in
  7309. export library is an alias of @samp{foo}, which gets the string name
  7310. in export table @samp{foo2}. The @samp{eoo} symbol is an data export
  7311. symbol, which gets in export table the name @samp{var1}.
  7312. The optional @code{LIBRARY <name>} command indicates the @emph{internal}
  7313. name of the output DLL. If @samp{<name>} does not include a suffix,
  7314. the default library suffix, @samp{.DLL} is appended.
  7315. When the .DEF file is used to build an application, rather than a
  7316. library, the @code{NAME <name>} command should be used instead of
  7317. @code{LIBRARY}. If @samp{<name>} does not include a suffix, the default
  7318. executable suffix, @samp{.EXE} is appended.
  7319. With either @code{LIBRARY <name>} or @code{NAME <name>} the optional
  7320. specification @code{BASE = <number>} may be used to specify a
  7321. non-default base address for the image.
  7322. If neither @code{LIBRARY <name>} nor @code{NAME <name>} is specified,
  7323. or they specify an empty string, the internal name is the same as the
  7324. filename specified on the command line.
  7325. The complete specification of an export symbol is:
  7326. @example
  7327. EXPORTS
  7328. ( ( ( <name1> [ = <name2> ] )
  7329. | ( <name1> = <module-name> . <external-name>))
  7330. [ @@ <integer> ] [NONAME] [DATA] [CONSTANT] [PRIVATE] [== <name3>] ) *
  7331. @end example
  7332. Declares @samp{<name1>} as an exported symbol from the DLL, or declares
  7333. @samp{<name1>} as an exported alias for @samp{<name2>}; or declares
  7334. @samp{<name1>} as a "forward" alias for the symbol
  7335. @samp{<external-name>} in the DLL @samp{<module-name>}.
  7336. Optionally, the symbol may be exported by the specified ordinal
  7337. @samp{<integer>} alias. The optional @samp{<name3>} is the to be used
  7338. string in import/export table for the symbol.
  7339. The optional keywords that follow the declaration indicate:
  7340. @code{NONAME}: Do not put the symbol name in the DLL's export table. It
  7341. will still be exported by its ordinal alias (either the value specified
  7342. by the .def specification or, otherwise, the value assigned by the
  7343. linker). The symbol name, however, does remain visible in the import
  7344. library (if any), unless @code{PRIVATE} is also specified.
  7345. @code{DATA}: The symbol is a variable or object, rather than a function.
  7346. The import lib will export only an indirect reference to @code{foo} as
  7347. the symbol @code{_imp__foo} (ie, @code{foo} must be resolved as
  7348. @code{*_imp__foo}).
  7349. @code{CONSTANT}: Like @code{DATA}, but put the undecorated @code{foo} as
  7350. well as @code{_imp__foo} into the import library. Both refer to the
  7351. read-only import address table's pointer to the variable, not to the
  7352. variable itself. This can be dangerous. If the user code fails to add
  7353. the @code{dllimport} attribute and also fails to explicitly add the
  7354. extra indirection that the use of the attribute enforces, the
  7355. application will behave unexpectedly.
  7356. @code{PRIVATE}: Put the symbol in the DLL's export table, but do not put
  7357. it into the static import library used to resolve imports at link time. The
  7358. symbol can still be imported using the @code{LoadLibrary/GetProcAddress}
  7359. API at runtime or by using the GNU ld extension of linking directly to
  7360. the DLL without an import library.
  7361. See ld/deffilep.y in the binutils sources for the full specification of
  7362. other DEF file statements
  7363. @cindex creating a DEF file
  7364. While linking a shared dll, @command{ld} is able to create a DEF file
  7365. with the @samp{--output-def <file>} command-line option.
  7366. @item Using decorations
  7367. @cindex Using decorations
  7368. Another way of marking symbols for export is to modify the source code
  7369. itself, so that when building the DLL each symbol to be exported is
  7370. declared as:
  7371. @example
  7372. __declspec(dllexport) int a_variable
  7373. __declspec(dllexport) void a_function(int with_args)
  7374. @end example
  7375. All such symbols will be exported from the DLL. If, however,
  7376. any of the object files in the DLL contain symbols decorated in
  7377. this way, then the normal auto-export behavior is disabled, unless
  7378. the @samp{--export-all-symbols} option is also used.
  7379. Note that object files that wish to access these symbols must @emph{not}
  7380. decorate them with dllexport. Instead, they should use dllimport,
  7381. instead:
  7382. @example
  7383. __declspec(dllimport) int a_variable
  7384. __declspec(dllimport) void a_function(int with_args)
  7385. @end example
  7386. This complicates the structure of library header files, because
  7387. when included by the library itself the header must declare the
  7388. variables and functions as dllexport, but when included by client
  7389. code the header must declare them as dllimport. There are a number
  7390. of idioms that are typically used to do this; often client code can
  7391. omit the __declspec() declaration completely. See
  7392. @samp{--enable-auto-import} and @samp{automatic data imports} for more
  7393. information.
  7394. @end table
  7395. @cindex automatic data imports
  7396. @item automatic data imports
  7397. The standard Windows dll format supports data imports from dlls only
  7398. by adding special decorations (dllimport/dllexport), which let the
  7399. compiler produce specific assembler instructions to deal with this
  7400. issue. This increases the effort necessary to port existing Un*x
  7401. code to these platforms, especially for large
  7402. c++ libraries and applications. The auto-import feature, which was
  7403. initially provided by Paul Sokolovsky, allows one to omit the
  7404. decorations to achieve a behavior that conforms to that on POSIX/Un*x
  7405. platforms. This feature is enabled with the @samp{--enable-auto-import}
  7406. command-line option, although it is enabled by default on cygwin/mingw.
  7407. The @samp{--enable-auto-import} option itself now serves mainly to
  7408. suppress any warnings that are ordinarily emitted when linked objects
  7409. trigger the feature's use.
  7410. auto-import of variables does not always work flawlessly without
  7411. additional assistance. Sometimes, you will see this message
  7412. "variable '<var>' can't be auto-imported. Please read the
  7413. documentation for ld's @code{--enable-auto-import} for details."
  7414. The @samp{--enable-auto-import} documentation explains why this error
  7415. occurs, and several methods that can be used to overcome this difficulty.
  7416. One of these methods is the @emph{runtime pseudo-relocs} feature, described
  7417. below.
  7418. @cindex runtime pseudo-relocation
  7419. For complex variables imported from DLLs (such as structs or classes),
  7420. object files typically contain a base address for the variable and an
  7421. offset (@emph{addend}) within the variable--to specify a particular
  7422. field or public member, for instance. Unfortunately, the runtime loader used
  7423. in win32 environments is incapable of fixing these references at runtime
  7424. without the additional information supplied by dllimport/dllexport decorations.
  7425. The standard auto-import feature described above is unable to resolve these
  7426. references.
  7427. The @samp{--enable-runtime-pseudo-relocs} switch allows these references to
  7428. be resolved without error, while leaving the task of adjusting the references
  7429. themselves (with their non-zero addends) to specialized code provided by the
  7430. runtime environment. Recent versions of the cygwin and mingw environments and
  7431. compilers provide this runtime support; older versions do not. However, the
  7432. support is only necessary on the developer's platform; the compiled result will
  7433. run without error on an older system.
  7434. @samp{--enable-runtime-pseudo-relocs} is not the default; it must be explicitly
  7435. enabled as needed.
  7436. @cindex direct linking to a dll
  7437. @item direct linking to a dll
  7438. The cygwin/mingw ports of @command{ld} support the direct linking,
  7439. including data symbols, to a dll without the usage of any import
  7440. libraries. This is much faster and uses much less memory than does the
  7441. traditional import library method, especially when linking large
  7442. libraries or applications. When @command{ld} creates an import lib, each
  7443. function or variable exported from the dll is stored in its own bfd, even
  7444. though a single bfd could contain many exports. The overhead involved in
  7445. storing, loading, and processing so many bfd's is quite large, and explains the
  7446. tremendous time, memory, and storage needed to link against particularly
  7447. large or complex libraries when using import libs.
  7448. Linking directly to a dll uses no extra command-line switches other than
  7449. @samp{-L} and @samp{-l}, because @command{ld} already searches for a number
  7450. of names to match each library. All that is needed from the developer's
  7451. perspective is an understanding of this search, in order to force ld to
  7452. select the dll instead of an import library.
  7453. For instance, when ld is called with the argument @samp{-lxxx} it will attempt
  7454. to find, in the first directory of its search path,
  7455. @example
  7456. libxxx.dll.a
  7457. xxx.dll.a
  7458. libxxx.a
  7459. xxx.lib
  7460. libxxx.lib
  7461. cygxxx.dll (*)
  7462. libxxx.dll
  7463. xxx.dll
  7464. @end example
  7465. before moving on to the next directory in the search path.
  7466. (*) Actually, this is not @samp{cygxxx.dll} but in fact is @samp{<prefix>xxx.dll},
  7467. where @samp{<prefix>} is set by the @command{ld} option
  7468. @samp{--dll-search-prefix=<prefix>}. In the case of cygwin, the standard gcc spec
  7469. file includes @samp{--dll-search-prefix=cyg}, so in effect we actually search for
  7470. @samp{cygxxx.dll}.
  7471. Other win32-based unix environments, such as mingw or pw32, may use other
  7472. @samp{<prefix>}es, although at present only cygwin makes use of this feature. It
  7473. was originally intended to help avoid name conflicts among dll's built for the
  7474. various win32/un*x environments, so that (for example) two versions of a zlib dll
  7475. could coexist on the same machine.
  7476. The generic cygwin/mingw path layout uses a @samp{bin} directory for
  7477. applications and dll's and a @samp{lib} directory for the import
  7478. libraries (using cygwin nomenclature):
  7479. @example
  7480. bin/
  7481. cygxxx.dll
  7482. lib/
  7483. libxxx.dll.a (in case of dll's)
  7484. libxxx.a (in case of static archive)
  7485. @end example
  7486. Linking directly to a dll without using the import library can be
  7487. done two ways:
  7488. 1. Use the dll directly by adding the @samp{bin} path to the link line
  7489. @example
  7490. gcc -Wl,-verbose -o a.exe -L../bin/ -lxxx
  7491. @end example
  7492. However, as the dll's often have version numbers appended to their names
  7493. (@samp{cygncurses-5.dll}) this will often fail, unless one specifies
  7494. @samp{-L../bin -lncurses-5} to include the version. Import libs are generally
  7495. not versioned, and do not have this difficulty.
  7496. 2. Create a symbolic link from the dll to a file in the @samp{lib}
  7497. directory according to the above mentioned search pattern. This
  7498. should be used to avoid unwanted changes in the tools needed for
  7499. making the app/dll.
  7500. @example
  7501. ln -s bin/cygxxx.dll lib/[cyg|lib|]xxx.dll[.a]
  7502. @end example
  7503. Then you can link without any make environment changes.
  7504. @example
  7505. gcc -Wl,-verbose -o a.exe -L../lib/ -lxxx
  7506. @end example
  7507. This technique also avoids the version number problems, because the following is
  7508. perfectly legal
  7509. @example
  7510. bin/
  7511. cygxxx-5.dll
  7512. lib/
  7513. libxxx.dll.a -> ../bin/cygxxx-5.dll
  7514. @end example
  7515. Linking directly to a dll without using an import lib will work
  7516. even when auto-import features are exercised, and even when
  7517. @samp{--enable-runtime-pseudo-relocs} is used.
  7518. Given the improvements in speed and memory usage, one might justifiably
  7519. wonder why import libraries are used at all. There are three reasons:
  7520. 1. Until recently, the link-directly-to-dll functionality did @emph{not}
  7521. work with auto-imported data.
  7522. 2. Sometimes it is necessary to include pure static objects within the
  7523. import library (which otherwise contains only bfd's for indirection
  7524. symbols that point to the exports of a dll). Again, the import lib
  7525. for the cygwin kernel makes use of this ability, and it is not
  7526. possible to do this without an import lib.
  7527. 3. Symbol aliases can only be resolved using an import lib. This is
  7528. critical when linking against OS-supplied dll's (eg, the win32 API)
  7529. in which symbols are usually exported as undecorated aliases of their
  7530. stdcall-decorated assembly names.
  7531. So, import libs are not going away. But the ability to replace
  7532. true import libs with a simple symbolic link to (or a copy of)
  7533. a dll, in many cases, is a useful addition to the suite of tools
  7534. binutils makes available to the win32 developer. Given the
  7535. massive improvements in memory requirements during linking, storage
  7536. requirements, and linking speed, we expect that many developers
  7537. will soon begin to use this feature whenever possible.
  7538. @item symbol aliasing
  7539. @table @emph
  7540. @item adding additional names
  7541. Sometimes, it is useful to export symbols with additional names.
  7542. A symbol @samp{foo} will be exported as @samp{foo}, but it can also be
  7543. exported as @samp{_foo} by using special directives in the DEF file
  7544. when creating the dll. This will affect also the optional created
  7545. import library. Consider the following DEF file:
  7546. @example
  7547. LIBRARY "xyz.dll" BASE=0x61000000
  7548. EXPORTS
  7549. foo
  7550. _foo = foo
  7551. @end example
  7552. The line @samp{_foo = foo} maps the symbol @samp{foo} to @samp{_foo}.
  7553. Another method for creating a symbol alias is to create it in the
  7554. source code using the "weak" attribute:
  7555. @example
  7556. void foo () @{ /* Do something. */; @}
  7557. void _foo () __attribute__ ((weak, alias ("foo")));
  7558. @end example
  7559. See the gcc manual for more information about attributes and weak
  7560. symbols.
  7561. @item renaming symbols
  7562. Sometimes it is useful to rename exports. For instance, the cygwin
  7563. kernel does this regularly. A symbol @samp{_foo} can be exported as
  7564. @samp{foo} but not as @samp{_foo} by using special directives in the
  7565. DEF file. (This will also affect the import library, if it is
  7566. created). In the following example:
  7567. @example
  7568. LIBRARY "xyz.dll" BASE=0x61000000
  7569. EXPORTS
  7570. _foo = foo
  7571. @end example
  7572. The line @samp{_foo = foo} maps the exported symbol @samp{foo} to
  7573. @samp{_foo}.
  7574. @end table
  7575. Note: using a DEF file disables the default auto-export behavior,
  7576. unless the @samp{--export-all-symbols} command-line option is used.
  7577. If, however, you are trying to rename symbols, then you should list
  7578. @emph{all} desired exports in the DEF file, including the symbols
  7579. that are not being renamed, and do @emph{not} use the
  7580. @samp{--export-all-symbols} option. If you list only the
  7581. renamed symbols in the DEF file, and use @samp{--export-all-symbols}
  7582. to handle the other symbols, then the both the new names @emph{and}
  7583. the original names for the renamed symbols will be exported.
  7584. In effect, you'd be aliasing those symbols, not renaming them,
  7585. which is probably not what you wanted.
  7586. @cindex weak externals
  7587. @item weak externals
  7588. The Windows object format, PE, specifies a form of weak symbols called
  7589. weak externals. When a weak symbol is linked and the symbol is not
  7590. defined, the weak symbol becomes an alias for some other symbol. There
  7591. are three variants of weak externals:
  7592. @itemize
  7593. @item Definition is searched for in objects and libraries, historically
  7594. called lazy externals.
  7595. @item Definition is searched for only in other objects, not in libraries.
  7596. This form is not presently implemented.
  7597. @item No search; the symbol is an alias. This form is not presently
  7598. implemented.
  7599. @end itemize
  7600. As a GNU extension, weak symbols that do not specify an alternate symbol
  7601. are supported. If the symbol is undefined when linking, the symbol
  7602. uses a default value.
  7603. @cindex aligned common symbols
  7604. @item aligned common symbols
  7605. As a GNU extension to the PE file format, it is possible to specify the
  7606. desired alignment for a common symbol. This information is conveyed from
  7607. the assembler or compiler to the linker by means of GNU-specific commands
  7608. carried in the object file's @samp{.drectve} section, which are recognized
  7609. by @command{ld} and respected when laying out the common symbols. Native
  7610. tools will be able to process object files employing this GNU extension,
  7611. but will fail to respect the alignment instructions, and may issue noisy
  7612. warnings about unknown linker directives.
  7613. @end table
  7614. @ifclear GENERIC
  7615. @lowersections
  7616. @end ifclear
  7617. @end ifset
  7618. @ifset XTENSA
  7619. @ifclear GENERIC
  7620. @raisesections
  7621. @end ifclear
  7622. @node Xtensa
  7623. @section @code{ld} and Xtensa Processors
  7624. @cindex Xtensa processors
  7625. The default @command{ld} behavior for Xtensa processors is to interpret
  7626. @code{SECTIONS} commands so that lists of explicitly named sections in a
  7627. specification with a wildcard file will be interleaved when necessary to
  7628. keep literal pools within the range of PC-relative load offsets. For
  7629. example, with the command:
  7630. @smallexample
  7631. SECTIONS
  7632. @{
  7633. .text : @{
  7634. *(.literal .text)
  7635. @}
  7636. @}
  7637. @end smallexample
  7638. @noindent
  7639. @command{ld} may interleave some of the @code{.literal}
  7640. and @code{.text} sections from different object files to ensure that the
  7641. literal pools are within the range of PC-relative load offsets. A valid
  7642. interleaving might place the @code{.literal} sections from an initial
  7643. group of files followed by the @code{.text} sections of that group of
  7644. files. Then, the @code{.literal} sections from the rest of the files
  7645. and the @code{.text} sections from the rest of the files would follow.
  7646. @cindex @option{--relax} on Xtensa
  7647. @cindex relaxing on Xtensa
  7648. Relaxation is enabled by default for the Xtensa version of @command{ld} and
  7649. provides two important link-time optimizations. The first optimization
  7650. is to combine identical literal values to reduce code size. A redundant
  7651. literal will be removed and all the @code{L32R} instructions that use it
  7652. will be changed to reference an identical literal, as long as the
  7653. location of the replacement literal is within the offset range of all
  7654. the @code{L32R} instructions. The second optimization is to remove
  7655. unnecessary overhead from assembler-generated ``longcall'' sequences of
  7656. @code{L32R}/@code{CALLX@var{n}} when the target functions are within
  7657. range of direct @code{CALL@var{n}} instructions.
  7658. For each of these cases where an indirect call sequence can be optimized
  7659. to a direct call, the linker will change the @code{CALLX@var{n}}
  7660. instruction to a @code{CALL@var{n}} instruction, remove the @code{L32R}
  7661. instruction, and remove the literal referenced by the @code{L32R}
  7662. instruction if it is not used for anything else. Removing the
  7663. @code{L32R} instruction always reduces code size but can potentially
  7664. hurt performance by changing the alignment of subsequent branch targets.
  7665. By default, the linker will always preserve alignments, either by
  7666. switching some instructions between 24-bit encodings and the equivalent
  7667. density instructions or by inserting a no-op in place of the @code{L32R}
  7668. instruction that was removed. If code size is more important than
  7669. performance, the @option{--size-opt} option can be used to prevent the
  7670. linker from widening density instructions or inserting no-ops, except in
  7671. a few cases where no-ops are required for correctness.
  7672. The following Xtensa-specific command-line options can be used to
  7673. control the linker:
  7674. @cindex Xtensa options
  7675. @table @option
  7676. @item --size-opt
  7677. When optimizing indirect calls to direct calls, optimize for code size
  7678. more than performance. With this option, the linker will not insert
  7679. no-ops or widen density instructions to preserve branch target
  7680. alignment. There may still be some cases where no-ops are required to
  7681. preserve the correctness of the code.
  7682. @item --abi-windowed
  7683. @itemx --abi-call0
  7684. Choose ABI for the output object and for the generated PLT code.
  7685. PLT code inserted by the linker must match ABI of the output object
  7686. because windowed and call0 ABI use incompatible function call
  7687. conventions.
  7688. Default ABI is chosen by the ABI tag in the @code{.xtensa.info} section
  7689. of the first input object.
  7690. A warning is issued if ABI tags of input objects do not match each other
  7691. or the chosen output object ABI.
  7692. @end table
  7693. @ifclear GENERIC
  7694. @lowersections
  7695. @end ifclear
  7696. @end ifset
  7697. @ifclear SingleFormat
  7698. @node BFD
  7699. @chapter BFD
  7700. @cindex back end
  7701. @cindex object file management
  7702. @cindex object formats available
  7703. @kindex objdump -i
  7704. The linker accesses object and archive files using the BFD libraries.
  7705. These libraries allow the linker to use the same routines to operate on
  7706. object files whatever the object file format. A different object file
  7707. format can be supported simply by creating a new BFD back end and adding
  7708. it to the library. To conserve runtime memory, however, the linker and
  7709. associated tools are usually configured to support only a subset of the
  7710. object file formats available. You can use @code{objdump -i}
  7711. (@pxref{objdump,,objdump,binutils.info,The GNU Binary Utilities}) to
  7712. list all the formats available for your configuration.
  7713. @cindex BFD requirements
  7714. @cindex requirements for BFD
  7715. As with most implementations, BFD is a compromise between
  7716. several conflicting requirements. The major factor influencing
  7717. BFD design was efficiency: any time used converting between
  7718. formats is time which would not have been spent had BFD not
  7719. been involved. This is partly offset by abstraction payback; since
  7720. BFD simplifies applications and back ends, more time and care
  7721. may be spent optimizing algorithms for a greater speed.
  7722. One minor artifact of the BFD solution which you should bear in
  7723. mind is the potential for information loss. There are two places where
  7724. useful information can be lost using the BFD mechanism: during
  7725. conversion and during output. @xref{BFD information loss}.
  7726. @menu
  7727. * BFD outline:: How it works: an outline of BFD
  7728. @end menu
  7729. @node BFD outline
  7730. @section How It Works: An Outline of BFD
  7731. @cindex opening object files
  7732. @include bfdsumm.texi
  7733. @end ifclear
  7734. @node Reporting Bugs
  7735. @chapter Reporting Bugs
  7736. @cindex bugs in @command{ld}
  7737. @cindex reporting bugs in @command{ld}
  7738. Your bug reports play an essential role in making @command{ld} reliable.
  7739. Reporting a bug may help you by bringing a solution to your problem, or
  7740. it may not. But in any case the principal function of a bug report is
  7741. to help the entire community by making the next version of @command{ld}
  7742. work better. Bug reports are your contribution to the maintenance of
  7743. @command{ld}.
  7744. In order for a bug report to serve its purpose, you must include the
  7745. information that enables us to fix the bug.
  7746. @menu
  7747. * Bug Criteria:: Have you found a bug?
  7748. * Bug Reporting:: How to report bugs
  7749. @end menu
  7750. @node Bug Criteria
  7751. @section Have You Found a Bug?
  7752. @cindex bug criteria
  7753. If you are not sure whether you have found a bug, here are some guidelines:
  7754. @itemize @bullet
  7755. @cindex fatal signal
  7756. @cindex linker crash
  7757. @cindex crash of linker
  7758. @item
  7759. If the linker gets a fatal signal, for any input whatever, that is a
  7760. @command{ld} bug. Reliable linkers never crash.
  7761. @cindex error on valid input
  7762. @item
  7763. If @command{ld} produces an error message for valid input, that is a bug.
  7764. @cindex invalid input
  7765. @item
  7766. If @command{ld} does not produce an error message for invalid input, that
  7767. may be a bug. In the general case, the linker can not verify that
  7768. object files are correct.
  7769. @item
  7770. If you are an experienced user of linkers, your suggestions for
  7771. improvement of @command{ld} are welcome in any case.
  7772. @end itemize
  7773. @node Bug Reporting
  7774. @section How to Report Bugs
  7775. @cindex bug reports
  7776. @cindex @command{ld} bugs, reporting
  7777. A number of companies and individuals offer support for @sc{gnu}
  7778. products. If you obtained @command{ld} from a support organization, we
  7779. recommend you contact that organization first.
  7780. You can find contact information for many support companies and
  7781. individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
  7782. distribution.
  7783. @ifset BUGURL
  7784. Otherwise, send bug reports for @command{ld} to
  7785. @value{BUGURL}.
  7786. @end ifset
  7787. The fundamental principle of reporting bugs usefully is this:
  7788. @strong{report all the facts}. If you are not sure whether to state a
  7789. fact or leave it out, state it!
  7790. Often people omit facts because they think they know what causes the
  7791. problem and assume that some details do not matter. Thus, you might
  7792. assume that the name of a symbol you use in an example does not
  7793. matter. Well, probably it does not, but one cannot be sure. Perhaps
  7794. the bug is a stray memory reference which happens to fetch from the
  7795. location where that name is stored in memory; perhaps, if the name
  7796. were different, the contents of that location would fool the linker
  7797. into doing the right thing despite the bug. Play it safe and give a
  7798. specific, complete example. That is the easiest thing for you to do,
  7799. and the most helpful.
  7800. Keep in mind that the purpose of a bug report is to enable us to fix
  7801. the bug if it is new to us. Therefore, always write your bug reports
  7802. on the assumption that the bug has not been reported previously.
  7803. Sometimes people give a few sketchy facts and ask, ``Does this ring a
  7804. bell?'' This cannot help us fix a bug, so it is basically useless. We
  7805. respond by asking for enough details to enable us to investigate.
  7806. You might as well expedite matters by sending them to begin with.
  7807. To enable us to fix the bug, you should include all these things:
  7808. @itemize @bullet
  7809. @item
  7810. The version of @command{ld}. @command{ld} announces it if you start it with
  7811. the @samp{--version} argument.
  7812. Without this, we will not know whether there is any point in looking for
  7813. the bug in the current version of @command{ld}.
  7814. @item
  7815. Any patches you may have applied to the @command{ld} source, including any
  7816. patches made to the @code{BFD} library.
  7817. @item
  7818. The type of machine you are using, and the operating system name and
  7819. version number.
  7820. @item
  7821. What compiler (and its version) was used to compile @command{ld}---e.g.
  7822. ``@code{gcc-2.7}''.
  7823. @item
  7824. The command arguments you gave the linker to link your example and
  7825. observe the bug. To guarantee you will not omit something important,
  7826. list them all. A copy of the Makefile (or the output from make) is
  7827. sufficient.
  7828. If we were to try to guess the arguments, we would probably guess wrong
  7829. and then we might not encounter the bug.
  7830. @item
  7831. A complete input file, or set of input files, that will reproduce the
  7832. bug. It is generally most helpful to send the actual object files
  7833. provided that they are reasonably small. Say no more than 10K. For
  7834. bigger files you can either make them available by FTP or HTTP or else
  7835. state that you are willing to send the object file(s) to whomever
  7836. requests them. (Note - your email will be going to a mailing list, so
  7837. we do not want to clog it up with large attachments). But small
  7838. attachments are best.
  7839. If the source files were assembled using @code{gas} or compiled using
  7840. @code{gcc}, then it may be OK to send the source files rather than the
  7841. object files. In this case, be sure to say exactly what version of
  7842. @code{gas} or @code{gcc} was used to produce the object files. Also say
  7843. how @code{gas} or @code{gcc} were configured.
  7844. @item
  7845. A description of what behavior you observe that you believe is
  7846. incorrect. For example, ``It gets a fatal signal.''
  7847. Of course, if the bug is that @command{ld} gets a fatal signal, then we
  7848. will certainly notice it. But if the bug is incorrect output, we might
  7849. not notice unless it is glaringly wrong. You might as well not give us
  7850. a chance to make a mistake.
  7851. Even if the problem you experience is a fatal signal, you should still
  7852. say so explicitly. Suppose something strange is going on, such as, your
  7853. copy of @command{ld} is out of sync, or you have encountered a bug in the
  7854. C library on your system. (This has happened!) Your copy might crash
  7855. and ours would not. If you told us to expect a crash, then when ours
  7856. fails to crash, we would know that the bug was not happening for us. If
  7857. you had not told us to expect a crash, then we would not be able to draw
  7858. any conclusion from our observations.
  7859. @item
  7860. If you wish to suggest changes to the @command{ld} source, send us context
  7861. diffs, as generated by @code{diff} with the @samp{-u}, @samp{-c}, or
  7862. @samp{-p} option. Always send diffs from the old file to the new file.
  7863. If you even discuss something in the @command{ld} source, refer to it by
  7864. context, not by line number.
  7865. The line numbers in our development sources will not match those in your
  7866. sources. Your line numbers would convey no useful information to us.
  7867. @end itemize
  7868. Here are some things that are not necessary:
  7869. @itemize @bullet
  7870. @item
  7871. A description of the envelope of the bug.
  7872. Often people who encounter a bug spend a lot of time investigating
  7873. which changes to the input file will make the bug go away and which
  7874. changes will not affect it.
  7875. This is often time consuming and not very useful, because the way we
  7876. will find the bug is by running a single example under the debugger
  7877. with breakpoints, not by pure deduction from a series of examples.
  7878. We recommend that you save your time for something else.
  7879. Of course, if you can find a simpler example to report @emph{instead}
  7880. of the original one, that is a convenience for us. Errors in the
  7881. output will be easier to spot, running under the debugger will take
  7882. less time, and so on.
  7883. However, simplification is not vital; if you do not want to do this,
  7884. report the bug anyway and send us the entire test case you used.
  7885. @item
  7886. A patch for the bug.
  7887. A patch for the bug does help us if it is a good one. But do not omit
  7888. the necessary information, such as the test case, on the assumption that
  7889. a patch is all we need. We might see problems with your patch and decide
  7890. to fix the problem another way, or we might not understand it at all.
  7891. Sometimes with a program as complicated as @command{ld} it is very hard to
  7892. construct an example that will make the program follow a certain path
  7893. through the code. If you do not send us the example, we will not be
  7894. able to construct one, so we will not be able to verify that the bug is
  7895. fixed.
  7896. And if we cannot understand what bug you are trying to fix, or why your
  7897. patch should be an improvement, we will not install it. A test case will
  7898. help us to understand.
  7899. @item
  7900. A guess about what the bug is or what it depends on.
  7901. Such guesses are usually wrong. Even we cannot guess right about such
  7902. things without first using the debugger to find the facts.
  7903. @end itemize
  7904. @node MRI
  7905. @appendix MRI Compatible Script Files
  7906. @cindex MRI compatibility
  7907. To aid users making the transition to @sc{gnu} @command{ld} from the MRI
  7908. linker, @command{ld} can use MRI compatible linker scripts as an
  7909. alternative to the more general-purpose linker scripting language
  7910. described in @ref{Scripts}. MRI compatible linker scripts have a much
  7911. simpler command set than the scripting language otherwise used with
  7912. @command{ld}. @sc{gnu} @command{ld} supports the most commonly used MRI
  7913. linker commands; these commands are described here.
  7914. In general, MRI scripts aren't of much use with the @code{a.out} object
  7915. file format, since it only has three sections and MRI scripts lack some
  7916. features to make use of them.
  7917. You can specify a file containing an MRI-compatible script using the
  7918. @samp{-c} command-line option.
  7919. Each command in an MRI-compatible script occupies its own line; each
  7920. command line starts with the keyword that identifies the command (though
  7921. blank lines are also allowed for punctuation). If a line of an
  7922. MRI-compatible script begins with an unrecognized keyword, @command{ld}
  7923. issues a warning message, but continues processing the script.
  7924. Lines beginning with @samp{*} are comments.
  7925. You can write these commands using all upper-case letters, or all
  7926. lower case; for example, @samp{chip} is the same as @samp{CHIP}.
  7927. The following list shows only the upper-case form of each command.
  7928. @table @code
  7929. @cindex @code{ABSOLUTE} (MRI)
  7930. @item ABSOLUTE @var{secname}
  7931. @itemx ABSOLUTE @var{secname}, @var{secname}, @dots{} @var{secname}
  7932. Normally, @command{ld} includes in the output file all sections from all
  7933. the input files. However, in an MRI-compatible script, you can use the
  7934. @code{ABSOLUTE} command to restrict the sections that will be present in
  7935. your output program. If the @code{ABSOLUTE} command is used at all in a
  7936. script, then only the sections named explicitly in @code{ABSOLUTE}
  7937. commands will appear in the linker output. You can still use other
  7938. input sections (whatever you select on the command line, or using
  7939. @code{LOAD}) to resolve addresses in the output file.
  7940. @cindex @code{ALIAS} (MRI)
  7941. @item ALIAS @var{out-secname}, @var{in-secname}
  7942. Use this command to place the data from input section @var{in-secname}
  7943. in a section called @var{out-secname} in the linker output file.
  7944. @var{in-secname} may be an integer.
  7945. @cindex @code{ALIGN} (MRI)
  7946. @item ALIGN @var{secname} = @var{expression}
  7947. Align the section called @var{secname} to @var{expression}. The
  7948. @var{expression} should be a power of two.
  7949. @cindex @code{BASE} (MRI)
  7950. @item BASE @var{expression}
  7951. Use the value of @var{expression} as the lowest address (other than
  7952. absolute addresses) in the output file.
  7953. @cindex @code{CHIP} (MRI)
  7954. @item CHIP @var{expression}
  7955. @itemx CHIP @var{expression}, @var{expression}
  7956. This command does nothing; it is accepted only for compatibility.
  7957. @cindex @code{END} (MRI)
  7958. @item END
  7959. This command does nothing whatever; it's only accepted for compatibility.
  7960. @cindex @code{FORMAT} (MRI)
  7961. @item FORMAT @var{output-format}
  7962. Similar to the @code{OUTPUT_FORMAT} command in the more general linker
  7963. language, but restricted to S-records, if @var{output-format} is @samp{S}
  7964. @cindex @code{LIST} (MRI)
  7965. @item LIST @var{anything}@dots{}
  7966. Print (to the standard output file) a link map, as produced by the
  7967. @command{ld} command-line option @samp{-M}.
  7968. The keyword @code{LIST} may be followed by anything on the
  7969. same line, with no change in its effect.
  7970. @cindex @code{LOAD} (MRI)
  7971. @item LOAD @var{filename}
  7972. @itemx LOAD @var{filename}, @var{filename}, @dots{} @var{filename}
  7973. Include one or more object file @var{filename} in the link; this has the
  7974. same effect as specifying @var{filename} directly on the @command{ld}
  7975. command line.
  7976. @cindex @code{NAME} (MRI)
  7977. @item NAME @var{output-name}
  7978. @var{output-name} is the name for the program produced by @command{ld}; the
  7979. MRI-compatible command @code{NAME} is equivalent to the command-line
  7980. option @samp{-o} or the general script language command @code{OUTPUT}.
  7981. @cindex @code{ORDER} (MRI)
  7982. @item ORDER @var{secname}, @var{secname}, @dots{} @var{secname}
  7983. @itemx ORDER @var{secname} @var{secname} @var{secname}
  7984. Normally, @command{ld} orders the sections in its output file in the
  7985. order in which they first appear in the input files. In an MRI-compatible
  7986. script, you can override this ordering with the @code{ORDER} command. The
  7987. sections you list with @code{ORDER} will appear first in your output
  7988. file, in the order specified.
  7989. @cindex @code{PUBLIC} (MRI)
  7990. @item PUBLIC @var{name}=@var{expression}
  7991. @itemx PUBLIC @var{name},@var{expression}
  7992. @itemx PUBLIC @var{name} @var{expression}
  7993. Supply a value (@var{expression}) for external symbol
  7994. @var{name} used in the linker input files.
  7995. @cindex @code{SECT} (MRI)
  7996. @item SECT @var{secname}, @var{expression}
  7997. @itemx SECT @var{secname}=@var{expression}
  7998. @itemx SECT @var{secname} @var{expression}
  7999. You can use any of these three forms of the @code{SECT} command to
  8000. specify the start address (@var{expression}) for section @var{secname}.
  8001. If you have more than one @code{SECT} statement for the same
  8002. @var{secname}, only the @emph{first} sets the start address.
  8003. @end table
  8004. @node GNU Free Documentation License
  8005. @appendix GNU Free Documentation License
  8006. @include fdl.texi
  8007. @node LD Index
  8008. @unnumbered LD Index
  8009. @printindex cp
  8010. @tex
  8011. % I think something like @@colophon should be in texinfo. In the
  8012. % meantime:
  8013. \long\def\colophon{\hbox to0pt{}\vfill
  8014. \centerline{The body of this manual is set in}
  8015. \centerline{\fontname\tenrm,}
  8016. \centerline{with headings in {\bf\fontname\tenbf}}
  8017. \centerline{and examples in {\tt\fontname\tentt}.}
  8018. \centerline{{\it\fontname\tenit\/} and}
  8019. \centerline{{\sl\fontname\tensl\/}}
  8020. \centerline{are used for emphasis.}\vfill}
  8021. \page\colophon
  8022. % Blame: doc@@cygnus.com, 28mar91.
  8023. @end tex
  8024. @bye