ld.texinfo 311 KB

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