ld-linux (8) - Linux man sida ld. so, ld-linux. so - dynamic linkerloader Den dynamiska länkaren kan köras antingen indirekt genom att köra ett dynamiskt länkat program eller bibliotek (i så fall inga kommandoradsalternativ till dynamiken linker kan överföras och i ELF-fallet körs den dynamiska länken som lagras i programmet. interp av programmet) eller direkt genom att köra: libld-linux. so. OPTIONS PROGRAM ARGUMENTS Beskrivning Programmen ld. so och ld-linux. so hittar och laddar de delade biblioteken som behövs av ett program, förbereder programmet att köra och kör sedan det. Linux-binärer kräver dynamisk länkning (länkning vid körtid) om inte - statiskt alternativ gavs till ld (1) under sammanställningen. Programmet ld. so hanterar a. out binärer, ett format som används för länge sedan ld-linux. so hanterar ELF (libld-linux. so.1 för libc5, libld-linux. so.2 för glibc2), som alla har använt i flera år nu. Annars har båda samma beteende och använder samma supportfiler och program ldd (1), ldconfig (8) och etcld. so. conf. När du löser bibliotekets beroenden inspekterar den dynamiska länkaren först varje beroende sträng för att se om den innehåller ett snedstreck (det kan inträffa om ett biblioteks söknamn som innehåller snedstreck specificerades vid länktiden). Om ett snedstreck hittas, tolkas beroendeberäkningen som ett (relativ eller absolut) söknamn, och biblioteket laddas med hjälp av det sökvägen. Om ett biblioteksberoende inte innehåller ett snedstreck, letas det efter i följande ordning: o (endast ELF) Användning av kataloger som anges i DTRPATHs dynamiska sektionsattribut för attributet binär om nuvarande och DTRUNPATH finns inte. Användning av DTRPATH avskrivs. Använda miljövariabeln LDLIBRARYPATH. Bortsett från om körbarheten är en uppsättning användare-IDset-grupp-ID binär, i vilket fall det ignoreras. (Endast ELF) Använd de kataloger som anges i DTRUNPATHs dynamiska sektionsattribut för binär om det finns närvarande. Från cachefilen etcld. so. cache. som innehåller en sammanställd lista över kandidatbibliotek som tidigare hittats i den utvidgade biblioteksvägen. Om emellertid binären var länkad med - z nodeflib linker-alternativet, hoppas biblioteken i standardbiblioteksstegen över. Bibliotek installerade i kataloger för hårdvarukapacitet (se nedan) föredras för andra bibliotek. I standardvägen lib. och sedan usrlib. Om binären var länkad med - z nodeflib linker-alternativet hoppas detta steg över. ORIGIN och rpath ld. so förstår strängen ORIGIN (eller motsvarande) i en rpath-specifikation (DTRPATH eller DTRUNPATH) för att innebära katalogen som innehåller programmet körbar. Således kan en applikation som ligger i somedirapp kompileras med gcc - Wl, - rpath, ORIGIN..lib så att den hittar ett associerat delat bibliotek i somedirlib oavsett var somedir finns i kataloghierarkin. Detta underlättar skapandet av nyckelfunktioner som inte behöver installeras i specialkataloger, men kan istället packas upp i någon katalog och fortfarande hitta egna delade bibliotek. Lista alla beroenden och hur de löses. - verifiera Verifiera att programmet är dynamiskt länkat och den här dynamiska länken kan hantera den. --Library-path PATH Använd PATH i stället för LDLIBRARYPATH miljövariabel inställning (se nedan). - inhibit-rpath LIST Ignorera RPATH och RUNPATH-information i objektnamn i LIST. Det här alternativet ignoreras om ld. so är set-user-ID eller set-group-ID. --Audit LIST Använd objekt som heter i LIST som revisorer. Hårdvarukapacitet Några bibliotek sammanställs med maskinvarespecifika instruktioner som inte finns på alla CPU-enheter. Sådana bibliotek bör installeras i kataloger vars namn definierar nödvändiga hårdvarukapacitet, t. ex. usrlibsse2. Den dynamiska länken kontrollerar dessa kataloger mot maskinens maskinvara och väljer den lämpligaste versionen av ett givet bibliotek. Möjligheter för maskinvarukapacitet kan kaskadas för att kombinera CPU-funktioner. Listan över stödda namn på hårdvarukapacitet beror på CPU: n. Följande namn är för närvarande kända: Alpha ev4, ev5, ev56, ev6, ev67 loongson2e, loongson2f, octeon, octeon2 PowerPC 4xxmac, altivec, arch205, arch206, bok, cellbe, dfp, efpdouble, efpsingle, fpu, icsnoop, mmu, notb , p5, p5, p4, p5, p5, p5, p4, p5, p5, p5, p3, p5, högtalare, hp, ldisp, msa, stfle, z900, z990, z9-109, z10, zarch x86 (endast 32 bitars) acpi, apic, clflush, cmov, cx8, dts, fxsr, ht, i386, i486, i586, i686, mca, mmx, mtrr, pat, pbe, pge, pn, pse36, sep, ss, sse, sse2, tm Miljö Det finns fyra viktiga miljövariabler. LDBINDNOW (libc5 glibc sedan 2.1.1) Om den ställs in på en nonempty-sträng, får den dynamiska länken att lösa alla symboler vid programstart i stället för att skjuta upp funktionskallupplösningen till den punkt när de först refereras. Detta är användbart när du använder en debugger. LDLIBRARYPATH En kolonnseparerad lista över kataloger för att söka efter ELF-bibliotek vid körningstid. Liknande PATH-miljövariabeln. Ignorerad i set-user-ID och set-group-ID-program. LDPRELOAD En lista över ytterligare, användardefinierade, ELF-delade bibliotek som ska laddas före alla andra. Objekten i listan kan separeras av mellanslag eller kolon. Detta kan användas för att selektivt åsidosätta funktioner i andra delade bibliotek. Biblioteken söks efter de regler som anges under BESKRIVNING. För binaries för användar-ID-ID-grupp-ID ELF-binärerna ignoreras förprogrammerade sökvägar som innehåller snedstreck, och bibliotek i standard-sökkataloger laddas endast om behörighetsbiten för användar-ID-id är aktiverad i bibliotekets fil. LDTRACELOADEDOBJECTS (endast ELF) Om den ställs in på en nonempty-sträng, får programmet att lista sina dynamiska biblioteksberoende, som om det körs av ldd (1) istället för att springa normalt. Då finns det många mer eller mindre obskilda variabler, många föråldrade eller bara för internt bruk. LDAOUTLIBRARYPATH (libc5) Version av LDLIBRARYPATH för endast a. out binärer. Gamla versioner av ld-linux. so.1 stöder också LDELFLIBRARYPATH. LDAOUTPRELOAD (libc5) Version av LDPRELOAD för endast a. out binärer. Gamla versioner av ld-linux. so.1 stöder också LDELFPRELOAD. LDAUDIT (glibc sedan 2.4) En kolonseparerad lista över användardefinierade, ELF-delade objekt som ska laddas före alla andra i en separat länknamnrymd (dvs en som inte inkräktar på de normala symbolbindningarna som skulle inträffa i processen). Dessa bibliotek kan användas för att granska driften av den dynamiska länken. LDAUDIT ignoreras för användar-IDset-grupp-ID-binärer. Den dynamiska länken kommer att underrätta revisionsbiblioteket vid så kallade revisionscheckpunkter, till exempel ladda ett nytt bibliotek, lösa en symbol eller ringa en symbol från ett annat delat objekt - genom att ringa en lämplig funktion i revisionsbiblioteket. För detaljer, se rtld-revision (7). Granskningsgränssnittet är i stor utsträckning kompatibelt med det som tillhandahålls på Solaris, som beskrivs i sin Linker and Libraries Guide. i kapitlet Runtime Linker Auditing Interface. LDBINDNOT (glibc sedan 2.1.95) Uppdatera inte GOT (Global offset-tabellen) och PLT (proceduren kopplingsbord) efter att ha löst upp en symbol. LDDEBUG (glibc sedan 2.1) Utför verbos information om den dynamiska länkaren. Om den är inställd på alla, skrivs all information om felsökning som den har om den är inställd för att skriva ut ett hjälpmeddelande om vilka kategorier som kan anges i denna miljövariabel. Sedan glibc 2.3.4 ignoreras LDDEBUG för binaries för användar-ID-id-grupp-ID. LDDEBUGOUTPUT (glibc sedan 2.1) Fil där LDDEBUG-utgången ska matas in, standard är standardutgång. LDDEBUGOUTPUT ignoreras för användar-ID-id-grupp-ID-binärer. LDDYNAMICWEAK (glibc sedan 2.1.91) Låt svaga symboler överskridas (återgå till gammalt glibc-beteende). Av säkerhetsskäl, eftersom glibc 2.3.4, ignoreras LDDYNAMICWEAK för binaries för användar-ID-id-grupp-ID. LDHWCAPMASK (glibc sedan 2.1) Mask för hårdvarukapacitet. LDKEEPDIR (a. out only) (libc5) Dont ignorera katalogen i namnen på a. out bibliotek som ska laddas. Användningen av detta alternativ är starkt avskräckt. LDNOWARN (a. out only) (libc5) Undertryck varningar om a. out bibliotek med inkompatibla mindre versionsnummer. LDORIGINPATH (glibc sedan 2.1) Sti där binären hittas (för icke-inställda användar-ID-program). Av säkerhetsskäl, eftersom glibc 2.4, ignoreras LDORIGINPATH för set-user-IDset-grupp-ID-binärer. LDPOINTERGUARD (glibc sedan 2.4) Ställ på 0 för att inaktivera pekskyddet. Alla andra värden möjliggör pekskyddet, vilket också är standardvärdet. Pekskyddet är en säkerhetsmekanism där vissa pekare som kodas lagras i skrivbart programminne (returadresser som sparas av setjmp (3) eller funktionspekare som används av olika glibc-internals) saknas halvvägs för att göra det svårare för en angripare att kapa pekare för användning i händelse av överbelastning av buffert eller stack-krossning. LDPROFILE (glibc sedan 2.1) Delat objekt som ska profileras, anges antingen som ett söknamn eller en sonnamn. Profileringsutgången skrivs till filen vars namn är: LDPROFILEOUTPUT LDPROFILE. profile. LDPROFILEOUTOUT (glibc sedan 2.1) Katalog där LDPROFILE-utmatning ska skrivas. Om denna variabel inte är definierad, eller definieras som en tom sträng, är standardvärdet vartmp. LDPROFILEOUTPUT ignoreras för set-user-ID och set-group-ID-program, som alltid använder varprofile. LDSHOWAUXV (glibc sedan 2.1) Visa extra array uppladdad från kärnan. Av säkerhetsskäl, eftersom glibc 2.3.5, ignoreras LDSHOWAUXV för binaries för användar-ID-id-grupp-ID. LDUSELOADBIAS Som standard (dvs om denna variabel inte är definierad) kommer exekveringar och prelinkade delade objekt att hedra basadresser till deras beroende biblioteken och (nonprelinked) positionsoberoende exekverbara körbara filer (PIEs) och andra delade objekt kommer inte att hedra dem. Om LDUSELOADBIAS är definierat med värdet, kommer både exekveringar och PIEs att hedra basadresserna. Om LDUSELOADBIAS definieras med värdet 0, kommer inte heller exekveringar eller PIE att hedra basadresserna. Denna variabel ignoreras av set-user-ID och set-group-ID-program. LDVERBOSE (glibc sedan 2.1) Om den är inställd på en nonempty-sträng, visar utmatningssymbolen information om programmet om LDTRACELOADEDOBJECTS-variabeln har ställts in. LDWARN (endast ELF) (glibc sedan 2.1.3) Om den är inställd på en nonempty-sträng, varna om olösta symboler. LDDARGV0 (libc5) argv 0 som ska användas av ldd (1) när ingen är närvarande. libld. so a. out dynamic linkerloader libld-linux. so. 1, 2 ELF dynamisk linkerloader etcld. so. cache Fil som innehåller en kompilerad lista över kataloger för att söka efter biblioteken och en ordnad lista över kandidatbibliotek. etcld. so. preload Fil som innehåller en mellanspecifik lista över ELF-delade bibliotek som ska laddas före programmet. lib. so shared libraries Funktionen ld. so är tillgänglig för körbara filer som kompileras med hjälp av libc version 4.4.3 eller senare. ELF-funktionaliteten är tillgänglig sedan Linux 1.1.52 och libc5. Finns det en uppsättning kommandoradsalternativ som övertygar gcc för att skapa en platt binär fil från en fristående källfil. Anta till exempel att innehållet i foo. c är nr externa referenser, inget att exportera till länken. Jag gillar att få en liten fil med bara maskininstruktionerna för den här funktionen, utan någon annan inredning. Sortera som en (DOS) - fil utom 32-bitars skyddat läge. frågade okt 30 09 på 0:26 De andra svaren är definitivt vägen att gå. Men jag var tvungen att ange ytterligare kommandoradsargument för att objcopy för att min produktion ska vara som förväntat. Observera att jag utvecklar 32-bitars kod på en 64-bitars maskin, följaktligen - m32-argumentet. Också, jag gillar intel-sammansättningssyntax bättre, så ska du se det i argumenten också. Okej, heres där jag var tvungen att ange att jag specifikt bara ville ha. textavsnittet: Det tog mig ungefär 2 timmar att läsa och prova olika alternativ innan jag tänkte ut det här. Förhoppningsvis sparar det någon annan den tiden. Du kan skicka alternativ till länken direkt med - Wl, ltlinker optiongt Den relevanta dokumentationen kopieras nedan från man gcc - Wl, alternativ Pass-alternativet som ett alternativ till länken. Om alternativet innehåller kommatecken delas det in i flera alternativ vid kommatecken. Du kan använda denna syntax för att skicka ett argument till alternativet. Till exempel, - Wl, - Map, output. map passerar - Map output. map till länken. När du använder GNU-länken kan du också få samma effekt med - Wl, - Mapoutput. map. Så när du sammanställer med gcc om du passerar - Wl, - oformatbinary genererar du en binär fil istället för elf-formatet. Där - oformatbinary berättar ld att generera en binär fil. Detta tar bort behovet att objcopy separat. Observera att --oformatbinary kan uttryckas som OUTPUTFORMAT (binär) från ett linker-skript. Om du vill hantera platta binärer, är det en stor chans att du skulle dra nytta av hög kontrollnivå som länkskript ger. svarade 6 maj 14 kl 18: 40 GNU linker ld är tänkt att täcka ett brett spektrum av situationer, och vara så kompatibelt som möjligt med andra länkare. Som ett resultat har du många alternativ att styra sitt beteende. Här är en sammanfattning av de alternativ som du kan använda på kommandoraden ld: Denna mängd kommandoradsalternativ kan verka skrämmande, men i verkligheten används några av dem i ett visst sammanhang. Exempelvis är en frekvent användning av ld att länka standard Unix-objektfiler på ett standard Unix-system som stöds. På ett sådant system, för att länka en fil hello. o. Detta berättar att ld ska producera en fil som heter output som ett resultat av att länka filen libcrt0.o med hello. o och biblioteket libc. a. vilket kommer från standardkatalogerna. (Se diskussionen om - l alternativet nedan.) Kommandoradsalternativen till ld kan anges i vilken ordning som helst, och kan upprepas efter vilja. Upprepa de flesta alternativ med ett annat argument kommer heller inte att ha någon ytterligare effekt, eller åsidosätta tidigare händelser (dem längre till vänster på kommandoraden) för det alternativet. Undantagen - som meningsfullt kan användas mer än en gång - är - A. - b (eller dess synonym-format), - defsym. - L. - l. - R. - u. och - ((eller dess synonym - startgrupp). Listan över objektfiler som ska länkas, visas som objfile. kan följa, föregå eller blandas med kommandoradsalternativ, förutom att ett objfilt argument kanske inte placeras mellan ett alternativ och dess argument. Vanligtvis kallas länken med minst en objektfil, men du kan ange andra former av binära inmatningsfiler med - l. - R och scriptkommandospråket. Om inga binära inmatningsfiler vid alla anges, länken producerar inte någon utmatning och utfärdar meddelandet Inga inmatningsfiler. Om länken inte kan känna igen formatet för en objektfil antas det att det är ett länkskript. Ett skript som anges på detta sätt huvudlänkarmen som används för länken (antingen standardlänkscriptet eller det som anges med - T). Den här funktionen tillåter länken att länka mot en fil som verkar vara ett objekt eller ett arkiv, men definierar bara en viss symbol värden, eller använder INPUT eller GROUP för att ladda andra objekt. Se sek tion Command Language. För alternativ vars namn är ett enstaka bokstav måste alternativargument antingen följa alternativet utan att ingripa mellanrummet eller ges som separata argument omedelbart efter det alternativ som kräver dem. För alternativ vars namn är flera bokstäver, kan antingen ett streck eller två föregå alternativnamnet till exempel, --oformat och - format är likvärdiga. Argument till alternativ med flera bokstäver måste antingen separeras från alternativnamnet med ett lika tecken, eller ges som separata argument omedelbart efter det alternativ som kräver dem. Exempelvis är --oformat srec och - oformatsrec ekvivalenta. Unika förkortningar av namnen på flera bokstäver accepteras. - b-inmatningsformat ld kan konfigureras för att stödja mer än en typ av objektfil. Om din ld är konfigurerad så kan du använda alternativet - b för att ange binärformat för inmatningsobjektfiler som följer detta alternativ på kommandoraden. Även om ld är konfigurerad för att stödja alternativa objektformat behöver du vanligtvis inte ange detta eftersom ld bör konfigureras att förvänta sig som standardinmatningsformat det vanligaste formatet på varje maskin. Inmatningsformat är en textsträng, namnet på ett visst format som stöds av BFD-biblioteken. (Du kan lista de tillgängliga binära formaten med objdump - i.) - format-inmatningsformat har samma effekt, liksom scriptkommandot TARGET. Se avsnitt BFD. Du kanske vill använda det här alternativet om du länkar filer med ett ovanligt binärt format. Du kan också använda - b för att byta format explicit (när du kopplar objektfiler i olika format), genom att inkludera - b-inmatningsformat före varje grupp av objektfiler i ett visst format. Standardformatet tas från miljövariabeln GNUTARGET. Du kan också definiera ingångsformatet från ett skript, med kommandot TARGET, se avsnittet Alternativkommandon. - Bstatic Länk inte till delade bibliotek. Detta är bara meningsfullt på plattformar för vilka delade bibliotek stöds. - Bdynamisk länk mot dynamiska bibliotek. Detta är bara meningsfullt på plattformar för vilka delade bibliotek stöds. Det här alternativet är normalt standard på sådana plattformar. - Bsymbolic När du skapar ett delat bibliotek, binda referenser till globala symboler till definitionen i det delade biblioteket, om det finns några. Normalt är det möjligt för ett program kopplat till ett delat bibliotek för att åsidosätta definitionen i det delade biblioteket. Det här alternativet är bara meningsfullt på ELF-plattformar som stöder delade bibliotek. - c MR-kommandofil För kompatibilitet med länkare som produceras av MR, accepterar ld skriptfiler som är skrivna i ett alternativt, begränsat kommandospråk som beskrivs i avsnittet MRI-kompatibla skriptfiler. Introducera MR-skriptfiler med alternativet - c använd alternativet - T att köra länkskript som är skrivna i det allmänna ld-skriptspråket. Om MRI-cmdfile inte existerar letar l efter det i katalogerna som anges av något - L alternativ. - d - dc - dp Dessa tre alternativ motsvarar flera former som stöds för kompatibilitet med andra länkare. De tilldelar utrymme till vanliga symboler även om en flyttbar utdatafil anges (med - r). Skriptkommandot FORCECOMMONALLOCATION har samma effekt. Se avsnittet Alternativkommandon. - defsym symboluttryck Skapa en global symbol i utdatafilen, innehållande den absoluta adressen som ges genom uttryck. Du kan använda det här alternativet så många gånger som nödvändigt för att definiera flera symboler i kommandoraden. En begränsad form av aritmetik stöds för uttrycket i detta sammanhang: Du kan ge en hexadecimal konstant eller namnet på en befintlig symbol, eller använda och - lägga till eller subtrahera hexadecimala konstanter eller symboler. Om du behöver mer utförliga uttryck, överväg att använda kommandospråket Länkar från ett skript (se avsnittet Uppgift: Definiera symboler). Obs! Det ska inte finnas något vitt utrymme mellan symbolen. lika signalen () och uttrycket. - embedded-relocs Det här alternativet är endast meningsfullt när du kopplar MIPS-inbyggd PIC-kod, genererad av alternativet - membedded-pic till GNU-kompilatorn och assembleren. Det får länken att skapa ett bord som kan användas vid körning för att flytta alla data som statiskt initierades till pekarvärden. Se koden i testutdrag-empic för detaljer. - e post Använd inmatning som den uttryckliga symbolen för att börja ditt program, men inte standardinställningen. Se avsnittet Ingångspunkten. för en diskussion av standardvärden och andra sätt att specificera ingångspunkten. - F - F-format ignoreras. Vissa äldre länkare använde detta alternativ i en kompileringsverktygskedja för att ange objektfilformat för både inmatnings - och utdatobjektfiler. Mekanismerna ld använder för detta ändamål (alternativen - b eller - format för inmatningsfiler, - oformat-alternativ eller TARGET-kommandot i länkskript för utdatafiler, GNUTARGET-miljövariabeln) är mer flexibla men ld accepterar - F-alternativet för kompatibilitet med skript som är skrivna för att ringa den gamla länken. - format input-format Synonym för - b-inmatningsformat. - g ignorerad Tillhandahålls för kompatibilitet med andra verktyg. - G-värde - G-värde Ställ in maximal storlek på objekt som ska optimeras med GP-registret till storlek under MIPS ECOFF. Ignorerad för andra objektfilformat. - hjälp Skriv ut en sammanfattning av kommandoradsalternativen på standardutmatningen och avsluta. - i Utför en inkrementell länk (samma som alternativ - r). - l ar Lägg arkivfilarkiv till listan över filer som ska länkas. Det här alternativet kan användas ett antal gånger. ld söker sökvägen för förekomster av lib ar. a för varje arkiv som anges. - L searchdir - L searchdir Lägg till sök sökväg till listan över sökvägar som ld ska söka efter arkivbibliotek och ld-kontrollskript. Du kan använda det här valet varje antal gånger. Katalogerna söks i den ordning som de anges på kommandoraden. Kataloger som anges på kommandoraden söks före standardkatalogerna. Alla - L alternativ gäller för alla - l alternativ, oavsett vilken ordning alternativen visas i. Banorna kan också anges i ett länkscript med SEARCHDIR-kommandot. Kataloger som anges på det här sättet söks på den punkt där länkskriptet visas i kommandoraden. - M Skriv ut (till standardutgången) en länkkarta - diagnostisk information om var symboler är mappade av ld. och information om global gemensam lagringstilldelning. - Map mapfile Skriv ut till filkartfilen en länkkarta - diagnostisk information om var symboler är mappade av ld. och information om global gemensam lagringstilldelning. - m emulering - m emulering Emulera emuleringslänken. Du kan lista tillgängliga emuleringar med alternativen --verbose eller - V. Standardvärdet beror på hur din ld har konfigurerats. - N Ställ in text - och datasektionerna för att läsas och skrivas. Sidelägg inte datasegmentet. Om utmatningsformat stöder magasnumren för Unix-stil, markera utmatningen som OMAGIC. - n Ställ in textsegmentet för att läsas och markera utdata som NMAGIC om möjligt. - noinhibit-exec Behåll den körbara utdatafilen när den fortfarande är användbar. Normalt producerar länken inte en utdatafil om den stöter på fel under länkprocessen som den går ut utan att skriva en utdatafil när den utfärdar något fel alls. - on-keep-memory ld optimerar normalt för hastighet över minnesanvändning genom att cacha symboltabellerna av inmatningsfiler i minnet. Det här alternativet berättar ld att istället optimera för minnesanvändning, genom att läsa om symboltabellerna efter behov. Det kan krävas om LD går tom för minnesutrymme när du kopplar en stor körbar. - o-utgång Använd utdata som namnet på programmet som produceras av ld om det här alternativet inte anges, namnet a. out används som standard. Skriptkommandot OUTPUT kan även ange utdatafilnamnet. - oformat utgångsformat ld kan konfigureras för att stödja mer än en typ av objektfil. Om din ld är konfigurerad på det här sättet kan du använda alternativet - oformat för att ange binärformat för utgångsobjektfilen. Även om ld är konfigurerad för att stödja alternativa objektformat behöver du vanligtvis inte ange detta, eftersom ld bör konfigureras att producera som vanligt utmatningsformat det vanligaste formatet på varje maskin. output-format är en textsträng, namnet på ett visst format som stöds av BFD-biblioteken. (Du kan lista de tillgängliga binära formaten med objdump - i.) Skriptkommandot OUTPUTFORMAT kan också ange utdataformat, men det här alternativet överstyrer det. Se avsnitt BFD. - R filnamn Läs symbolnamn och deras adresser från filnamn. men flytta inte den eller ta den med i utmatningen. Detta låter din utdatafil hänvisa symboliskt till absoluta minnesplatser som definieras i andra program. - relax Ett alternativ med maskinberoende effekter. På vissa plattformar utförs alternativet - relax globala optimeringar som blir möjliga när länken löser adressering i programmet, till exempel avkopplande adresslägen och syntetisering av nya instruktioner i utgångsobjektfilen. - retain-symbols-fil filnamn behåll endast de symboler som anges i filfilnamnet. kassera alla andra. filnamn är helt enkelt en platt fil med ett symbolnamn per rad. Det här alternativet är särskilt användbart i miljöer där ett stort globalt symboltabell ackumuleras gradvis för att spara speltidminne. - håll-symboler-filen kasserar inte odefinierade symboler eller symboler som behövs för flyttningar. Du får bara ange - hålla-symboler-filen en gång i kommandoraden. Det överträder - s och - S. - r Generera omflyttningsbar utgång - dvs. generera en utdatafil som i sin tur kan fungera som input till ld. Detta kallas ofta partiell länkning. Som en bieffekt, i miljöer som stöder standard Unix magiska tal, ställer det här alternativet också utmatningsfilerna magiskt nummer till OMAGIC. Om det här alternativet inte anges, produceras en absolut fil. När du kopplar C-program löser detta alternativ inte referenser till konstruktörer för att göra det, använd - Ur. Detta alternativ gör detsamma som - i. - S Omit debugger-symbolinformation (men inte alla symboler) från utdatafilen. - s Släpp all symbolinformation från utdatafilen. - delat Skapa ett delat bibliotek. Detta stöds för närvarande endast på ELF - och SunOS-plattformar. På SunOS skapar länken automatiskt ett delat bibliotek om alternativet - e inte används och det finns odefinierade symboler i länken. - sort-common Normalt, när ld placerar de globala vanliga symbolerna i lämpliga utgångssektioner, sorterar den dem efter storlek. Först kommer alla en byte symboler, då alla två byte, då alla fyra byte, och sedan allt annat. Detta för att förhindra mellanrum mellan symboler på grund av anpassningsbegränsningar. Det här alternativet inaktiverar den sorteringen. - split-by-reloc count Beräknar att skapa extra sektioner i utdatafilen så att ingen enskild utmatningsdel i filen innehåller mer än räkneförflyttningar. Detta är användbart när du genererar enorma relokatable för nedladdning i vissa realtidskärnor med COFF-objektfilformatet eftersom COFF inte kan representera mer än 65535 flyttningar i ett enda avsnitt. Observera att detta inte fungerar med objektfilformat som inte stöder godtyckliga avsnitt. Länkaren delar inte upp enskilda ingångssektioner för omfördelning, så om en enda ingångssektion innehåller mer än räkneförflyttningar kommer en utmatningssektion att innehålla så många omlokaliseringar. - split-för-fil som liknar - split-by-reloc men skapar en ny utmatningssektion för varje inmatningsfil. - statistik Beräkna och visa statistik om länkens funktion, t. ex. exekveringstid och minnesanvändning. - Tbss org - Tdata org - Ttext org Använd org som startadress för respektive - bss. data. eller textsegmentet i utdatafilen. org måste vara ett enda hexadecimalt heltal för kompatibilitet med andra länkare, du kan utelämna den ledande 0x som vanligtvis är associerad med hexadecimala värden. - T commandfile - T commandfile Läs länkkommandon från filkommandofilen. Dessa kommandon ersätter ld s standardlänkscript (istället för att lägga till det), så commandfile måste ange allt som behövs för att beskriva målformatet. Se avsnitt Kommandospråk. Om kommandofilen inte existerar letar l efter det i de kataloger som anges av några föregående - L alternativ. Multipla - T alternativ ackumuleras. - t Skriv ut namnen på inmatningsfilerna som ld behandlar dem. - traditionellt format För vissa mål är produktionen av ld olika på något sätt från produktionen av någon befintlig länk. Denna omkopplare begär ld att istället använda det traditionella formatet. På SunOS kombinerar ld exempelvis dubbla poster i symbolsträngtabellen. Detta kan minska storleken på en utdatafil med fullständig felsökningsinformation med över 30 procent. Tyvärr kan SunOS dbx-programmet inte läsa det resulterande programmet (gdb har inga problem). Konverteraren - traditional-format berättar att ld inte kombinerar dubbla poster. - u symbol Force-symbol som ska matas in i utdatafilen som en odefinierad symbol. Om du gör det kan du till exempel utlösa koppling av ytterligare moduler från standardbibliotek. - u kan upprepas med olika alternativargument för att ange ytterligare odefinierade symboler. - Ur För något annat än C-program, motsvarar det här alternativet - r. det genererar flyttbar utgång - dvs en utdatafil som i sin tur kan fungera som input till ld. När man kopplar C-program löser - Ur referenser till konstruktörer, till skillnad från - r. Det fungerar inte att använda - Er på filer som var själva kopplade till - Un när konstruktörstabellen har byggts kan den inte läggas till. Använd-Endast för den sista partiella länken, och - r för de andra. --verbose Visa versionsnumret för ld och lista de länkaremuleringar som stöds. Visa vilka inmatningsfiler som kan och kan inte öppnas. - v - V Visa versionsnumret för ld. Alternativet - V listar också de stödda emuleringarna. - version Visa versionsnumret för ld och exit. - varn-vanlig Varning när en gemensam symbol kombineras med en annan gemensam symbol eller med en symboldefinition. Unix-länkar tillåter detta lite slarvigt träning, men länkar på andra operativsystem gör det inte. Med det här alternativet kan du hitta potentiella problem från att kombinera globala symboler. Tyvärr använder vissa C-bibliotek denna övning, så du kan få några varningar om symboler i biblioteken och i dina program. Det finns tre typer av globala symboler, illustreras här med C-exempel: int I 1 En definition, som går i den initialiserade datafelningen i utdatafilen. extern int I En odefinierad referens, som inte allokerar utrymme. Det måste vara antingen en definition eller en gemensam symbol för variabeln någonstans. int jag En vanlig symbol. Om det bara finns (en eller flera) vanliga symboler för en variabel, går det i den oinitierade dataområdet för utdatafilen. Linker sammanfogar flera vanliga symboler för samma variabel i en enda symbol. Om de har olika storlekar, väljer den den största storleken. Länkaren gör en gemensam symbol till en deklaration, om det finns en definition av samma variabel. Det varna gemensamma alternativet kan producera fem typer av varningar. Varje varning består av ett par linjer: den första beskriver symbolen som bara stött på, och den andra beskriver den tidigare symbolen som möter samma namn. Ett eller båda av de två symbolerna kommer att vara en gemensam symbol. Att sätta en gemensam symbol i en referens, eftersom det redan finns en definition för symbolen. Omvandlar en gemensam symbol till en referens, eftersom en senare definition av symbolen uppträder. Detta är detsamma som i föregående fall, förutom att symbolerna uppträder i en annan ordning. Sammanslagning av en gemensam symbol med en tidigare gemensam gemensam symbol med samma storlek. Sammanslagning av en gemensam symbol med en tidigare större gemensam symbol. Sammanslagning av en gemensam symbol med en tidigare mindre gemensam symbol. Detta är detsamma som i föregående fall, förutom att symbolerna uppträder i en annan ordning. - warn-constructors Varning om några globala konstruktörer används. Detta är endast användbart för ett fåtal objektfilformat. För format som COFF eller ELF kan länken inte detektera användningen av globala konstruktörer. - varna en gång Varna endast en gång för varje odefinierad symbol, snarare än en gång per modul som refererar till den. For each archive mentioned on the command line, include every object file in the archive in the link, rather than searching the archive for the required object files. This is normally used to turn an archive file into a shared library, forcing every object to be included in the resulting shared library. - X Delete all temporary local symbols. For most targets, this is all local symbols whose names begin with L. - x Delete all local symbols. - y symbol Print the name of each linked file in which symbol appears. This option may be given any number of times. On many systems it is necessary to prepend an underscore. This option is useful when you have an undefined symbol in your link but dont know where the reference is coming from. -( archives -) --start-group archives --end-group The archives should be a list of archive files. They may be either explicit file names, or - l options. The specified archives are searched repeatedly until no new undefined references are created. Normally, an archive is searched only once in the order that it is specified on the command line. If a symbol in that archive is needed to resolve an undefined symbol referred to by an object in an archive that appears later on the command line, the linker would not be able to resolve that reference. By grouping the archives, they all be searched repeatedly until all possible references are resolved. Using this option has a significant performance cost. It is best to use it only when there are unavoidable circular references between two or more archives. Go to the first. previous. Nästa. last section, table of contents. Linux and Unix ld command ld combines a number of object and archive files, relocates their data and ties up symbol references. Usually the last step in compiling a program is to run ld. ld accepts Linker Command Language files written in a superset of ATampT s Link Editor Command Language syntax, to provide explicit and total control over the linking process. For full details on the ld command language, see the ld info page. Here, well cover a broad overview of how to use GNU ld, which is used in most versions of Linux . This version of ld uses the general purpose BFD libraries to operate on object files. This allows ld to read, combine, and write object files in many different formats: for example, COFF or a. out . Different formats may be linked together to produce any available kind of object file. Aside from its flexibility, the GNU linker is more helpful than other linkers in providing diagnostic information. Many linkers abandon execution immediately upon encountering an error whenever possible, ld continues executing, allowing you to identify other errors (or, in some cases, to get an output file in spite of the error). The GNU linker ld is meant to cover a broad range of situations, and to be as compatible as possible with other linkers. As a result, you have many choices to control its behavior. The linker supports many command-line options, but in actual practice few of them are used in any particular context. For instance, a frequent use of ld is to link standard Unix object files on a standard, supported Unix system. On such a system, to link a file hello. o : This tells ld to produce a file called output as the result of linking the file libcrt0.o with hello. o and the library libc. a , which will come from the standard search directories. See the - l option below. Some of the command-line options to ld may be specified at any point in the command line. However, options which refer to files, such as - l or - T . cause the file to be read at the point at which the option appears in the command line, relative to the object files and other file options. Repeating non-file options with a different argument will either have no further effect, or override prior occurrences (those further to the left on the command line) of that option. Options which may be meaningfully specified more than once are noted in the descriptions below. Non-option arguments are object files or archives which are to be linked together. They may follow, precede, or be mixed in with command-line options, except that an object file argument may not be placed between an option and its argument. Usually the linker is invoked with at least one object file, but you can specify other forms of binary input files using - l . - R . and the script command language. If no binary input files at all are specified, the linker does not produce any output, and issues the message No input files . If the linker cannot recognize the format of an object file, it will assume that it is a linker script. A script specified in this way augments the main linker script used for the link (either the default linker script or the one specified by using - T ). This feature permits the linker to link against a file which appears to be an object or an archive. but actually merely defines some symbol values, or uses INPUT or GROUP to load other objects. Specifying a script in this way merely augments the main linker script, with the extra commands placed after the main script use the - T option to replace the default linker script entirely, but note the effect of the INSERT command. For options whose names are a single letter, option arguments must either follow the option letter without intervening whitespace. or be given as separate arguments immediately following the option that requires them. For options whose names are multiple letters, either one dash or two can precede the option name for example, - trace-symbol and --trace-symbol are equivalent. Note that there is one exception to this rule: Multiple letter options that start with a lower case o can only be preceded by two dashes. This is to reduce confusion with the - o option. So for example - omagic sets the output file name to magic whereas --omagic sets the NMAGIC flag on the output. Arguments to multiple-letter options must either be separated from the option name by an equals sign, or be given as separate arguments immediately following the option that requires them. For example, --trace-symbol foo and --trace-symbolfoo are equivalent. Unique abbreviations of the names of multiple-letter options are accepted. Note that if the linker is being invoked indirectly, via a compiler driver (e. g. gcc ) then all the linker command line options should be prefixed by - Wl . (or whatever is appropriate for the particular compiler driver) like this: This is important, because otherwise the compiler driver program may silently drop the linker options, resulting in a bad link. Confusion may also arise when passing options that require values through a driver, as the use of a space between option and argument acts as a separator, and causes the driver to pass only the option to the linker and the argument to the compiler. In this case, it is simplest to use the joined forms of both single - and multiple-letter options, such as: Here is a table of the generic command line switches accepted by the GNU linker: Read command-line options from file . The options read are inserted in place of the original file option. If file does not exist, or cannot be read, then the option will be treated literally, and not removed. Options in file are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes. Any character (including a backslash) may be included by prefixing the character to be included with a backslash. The file may itself contain additional file options any such options will be processed recursively . This option is supported for HP-UX compatibility. The keyword argument must be one of the strings archive . shared . or default . - aarchive is functionally equivalent to - Bstatic . and the other two keywords are functionally equivalent to - Bdynamic . This option may be used any number of times. Adds AUDITLIB to the DTAUDIT entry of the dynamic section. AUDITLIB is not checked for existence, nor will it use the DTSONAME specified in the library. If specified multiple times DTAUDIT will contain a colon separated list of audit interfaces to use. If the linker finds an object with an audit entry while searching for shared libraries, it will add a corresponding DTDEPAUDIT entry in the output file. This option is only meaningful on ELF platforms supporting the rtld-audit interface. In the current release of ld . this option is useful only for the Intel 960 family of architectures. In that ld configuration, the architecture argument identifies the particular architecture in the 960 family, enabling some safeguards and modifying the archive-library search path. Future releases of ld may support similar functionality for other architecture families. ld may be configured to support more than one kind of object file. If your ld is configured this way, you can use the - b option to specify the binary format for input object files that follow this option on the command line. Even when ld is configured to support alternative object formats, you dont usually need to specify this, as ld should be configured to expect as a default input format the most usual format on each machine. input-format is a text string, the name of a particular format supported by the BFD libraries. You can list the available binary formats with objdump - i . You may want to use this option if you are linking files with an unusual binary format. You can also use - b to switch formats explicitly (when linking object files of different formats), by including - b input-format before each group of object files in a particular format. The default format is taken from the environment variable GNUTARGET. You can also define the input format from a script, using the command TARGET For compatibility with linkers produced by MRI, ld accepts script files written in an alternate, restricted command language, described in the MRI Compatible Script Files section of GNU ld documentation. Introduce MRI script files with the option - c use the - T option to run linker scripts written in the general-purpose ld scripting language. If MRI-cmdfile does not exist, ld looks for it in the directories specified by any - L options. These three options are equivalent multiple forms are supported for compatibility with other linkers. They assign space to common symbols even if a relocatable output file is specified (with - r ). The script command FORCECOMMONALLOCATION has the same effect. Adds AUDITLIB to the DTDEPAUDIT entry of the dynamic section. AUDITLIB is not checked for existence, nor will it use the DTSONAME specified in the library. If specified multiple times DTDEPAUDIT will contain a colon separated list of audit interfaces to use. This option is only meaningful on ELF platforms supporting the rtld-audit interface. The - P option is provided for Solaris compatibility. Use entry as the explicit symbol for beginning execution of your program, rather than the default entry point. If there is no symbol named entry . the linker will try to parse entry as a number, and use that as the entry address (the number will be interpreted in base 10 you may use a leading 0x for base 16, or a leading 0 for base 8). Specifies a list of archive libraries from which symbols should not be automatically exported. The library names may be delimited by commas or colons. Specifying --exclude-libs ALL excludes symbols in all archive libraries from automatic export. This option is available only for the i386 PE targeted port of the linker and for ELF targeted ports. For i386 PE, symbols explicitly listed in a. def file are still exported, regardless of this option. For ELF targeted ports, symbols affected by this option will be treated as hidden. Specifies a list of object files or archive members, from which symbols should not be automatically exported, but which should be copied wholesale into the import library being generated during the link. The module names may be delimited by commas or colons, and must match exactly the filenames used by ld to open the files for archive members, this is simply the member name, but for object files the name listed must include and match precisely any path used to specify the input file on the linkers command-line. This option is available only for the i386 PE targeted port of the linker. Symbols explicitly listed in a. def file are still exported, regardless of this option. When creating a dynamically linked executable, using the - E option or the --export-dynamic option causes the linker to add all symbols to the dynamic symbol table. The dynamic symbol table is the set of symbols which are visible from dynamic objects at run time. If you do not use either of these options (or use the --no-export-dynamic option to restore the default behavior), the dynamic symbol table will normally contain only those symbols which are referenced by some dynamic object mentioned in the link. If you use dlopen to load a dynamic object which needs to refer back to the symbols defined by the program, rather than some other dynamic object, then you will probably need to use this option when linking the program itself. You can also use the dynamic list to control what symbols should be added to the dynamic symbol table if the output format supports it. See the description of --dynamic-list . Note that this option is specific to ELF targeted ports. PE targets support a similar function to export all symbols from a DLL or EXE see the description of --export-all-symbols below. Link big-endian objects. This affects the default output format. Link little-endian objects. This affects the default output format. When creating an ELF shared object, set the internal DTAUXILIARY field to the specified name. This tells the dynamic linker that the symbol table of the shared object should be used as an auxiliary filter on the symbol table of the shared object name. If you later link a program against this filter object, then, when you run the program, the dynamic linker will see the DTAUXILIARY field. If the dynamic linker resolves any symbols from the filter object, it will first check whether there is a definition in the shared object name. If there is one, it will be used instead of the definition in the filter object. The shared object name need not exist. Thus the shared object name may be used to provide an alternative implementation of certain functions, perhaps for debugging or for machine specific performance. This option may be specified more than once. The DTAUXILIARY entries will be created in the order in which they appear on the command line. When creating an ELF shared object, set the internal DTFILTER field to the specified name. This tells the dynamic linker that the symbol table of the shared object which is being created should be used as a filter on the symbol table of the shared object name. If you later link a program against this filter object, then, when you run the program, the dynamic linker will see the DTFILTER field. The dynamic linker will resolve symbols according to the symbol table of the filter object as usual, but it will actually link to the definitions found in the shared object name. Thus the filter object can be used to select a subset of the symbols provided by the object name. Some older linkers used the - F option throughout a compilation toolchain for specifying object-file format for both input and output object files. The GNU linker uses other mechanisms for this purpose: the - b . --format . --oformat options, the TARGET command in linker scripts, and the GNUTARGET environment variable. The GNU linker will ignore the - F option when not creating an ELF shared object. When creating an ELF executable or shared object, call NAME when the executable or shared object is unloaded, by setting DTFINI to the address of the function. By default, the linker uses fini as the function to call. Ignored. Provided for compatibility with other tools. Set the maximum size of objects to be optimized using the GP register to size. This is only meaningful for object file formats such as MIPS ECOFF which supports putting large and small objects into different sections. This is ignored for other object file formats. When creating an ELF shared object, set the internal DTSONAME field to the specified name. When an executable is linked with a shared object which has a DTSONAME field, then when the executable is run the dynamic linker will attempt to load the shared object specified by the DTSONAME field rather than the using the file name given to the linker. Perform an incremental link (same as option - r ). When creating an ELF executable or shared object, call NAME when the executable or shared object is loaded, by setting DTINIT to the address of the function. By default, the linker uses init as the function to call. Add the archive or object file specified by namespec to the list of files to link. This option may be used any number of times. If namespec is of the form : filename . ld will search the library path for a file called filename . otherwise it will search the library path for a file called lib namespec. a . On systems which support shared libraries, ld may also search for files other than lib namespec. a . Specifically, on ELF and SunOS systems, ld will search a directory for a library called lib namespec. so before searching for one called lib namespec. a . By convention, a. so extension indicates a shared library. Note that this behavior does not apply to : filename . which always specifies a file called filename . The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again. See the -( option for a way to force the linker to search archives multiple times. You may list the same archive multiple times on the command line. This type of archive searching is standard for Unix linkers. However, if you are using ld on AIX. note that it is different from the behaviour of the AIX linker. Add path searchdir to the list of paths that ld will search for archive libraries and ld control scripts. You may use this option any number of times. The directories are searched in the order in which they are specified on the command line. Directories specified on the command line are searched before the default directories. All - L options apply to all - l options, regardless of the order in which the options appear. - L options do not affect how ld searches for a linker script unless - T option is specified. If searchdir begins with , then the will be replaced by the sysroot prefix, a path specified when the linker is configured. The default set of paths searched (without bei ng specified with - L ) depends on which emulation mode ld is using, and in some cases also on how it was configured at build time. The paths can also be specified in a link script with the SEARCHDIR command. Directories specified this way are searched at the point in which the linker script appears in the command line. Emulate the emulation linker. You can list the available emulations with the --verbose or - V options. If the - m option is not used, the emulation is taken from the LDEMULATION environment variable, if that is defined. Otherwise, the default emulation depends upon how the linker was configured. Print a link map to the standard output. A link map provides information about the link, including the following: Where object files are mapped into memory. How common symbols are allocated. All archive members included in the link, with a mention of the symbol which caused the archive member to be brought in. The values assigned to symbols. Note: symbols whose values are computed by an expression which involves a reference to a previous value of the same symbol may not have correct result displayed in the link map. This is because the linker discards intermediate results and only retains the final value of an expression. Under such circumstances the linker will display the final value enclosed by square brackets. Thus for example a linker script containing:will produce the following output in the link map if the - M option is used: Turn off page alignment of sections, and disable linking against shared libraries. If the output format supports Unix style magic numbers, mark the output as NMAGIC. Set the text and data sections to be readable and writable. Also, do not page-align the data segment, and disable linking against shared libraries. If the output format supports Unix style magic numbers, mark the output as OMAGIC. Note: Although a writable text section is allowed for PE-COFF targets, it does not conform to the format specification published by Microsoft . This option negates most of the effects of the - N option. It sets the text section to be read-only, and forces the data segment to be page-aligned. Note - this option does not enable linking against shared libraries. Use - Bdynamic for this. Use output as the name for the program produced by ld if this option is not specified, the name a. out is used by default. The script command OUTPUT can also specify the output file name. If level is a numeric value greater than zero ld optimizes the output. This might take significantly longer and therefore probably should only be enabled for the final binary. At the moment this option only affects ELF shared library generation. Future releases of the linker may make more use of this option. Also currently there is no difference in the linkers behaviour for different non-zero values of this option. Again this may change with future releases. Leave relocation sections and contents in fully linked executables. Post link analysis and optimization tools may need this information in order to perform correct modifications of executables. This results in larger executables. This option is currently only supported on ELF platforms. Force the output file to have dynamic sections. This option is specific to VxWorks targets. Generate relocatable output: i. e. generate an output file that can in turn serve as input to ld . This is often called partial linking. As a side effect, in environments that support standard Unix magic numbers, this option also sets the output files magic number to OMAGIC. If this option is not specified, an absolute file is produced. When linking C programs, this option will not resolve references to constructors to do that, use - Ur . When an input file does not have the same format as the output file, partial linking is only supported if that input file does not contain any relocations. Different output formats can have further restrictions for example some a. out - based formats do not support partial linking with input files in other formats at all. This option does the same thing as - i . Read symbol names and their addresses from filename . but do not relocate it or include it in the output. This allows your output file to refer symbolically to absolute locations of memory defined in other programs. You may use this option more than once. For compatibility with other ELF linkers, if the - R option is followed by a directory name, rather than a file name, it is treated as the - rpath option. Omit all symbol information from the output file. Use scriptfile as the linker script. This script replaces ld s default linker script (rather than adding to it), so commandfile must specify everything necessary to describe the output file. If scriptfile does not exist in the current directory, ld looks for it in the directories specified by any preceding - L options. Multiple - T options accumulate. Use scriptfile as the default linker script. This option is similar to the --script option except that processing of the script is delayed until after the rest of the command line has been processed. This allows options placed after the --default-script option on the command line to affect the behaviour of the linker script, which can be important when the linker command line cannot be directly controlled by the user. (e. g. because the command line is being constructed by another tool, such as gcc ). Force symbol to be entered in the output file as an undefined symbol. Doing this may, for example, trigger linking of additional modules from standard libraries. - u may be repeated with different option arguments to enter additional undefined symbols. This option is equivalent to the EXTERN linker script command. For anything other than C programs, this option is equivalent to - r . it generates relocatable output i. e. an output file that can in turn serve as input to ld . When linking C programs, - Ur does resolve references to constructors, unlike - r . It does not work to use - Ur on files that were themselves linked with - Ur once the constructor table has been built, it cannot be added to. Use - Ur only for the last partial link, and - r for the others. Creates a separate output section for every input section matching SECTION, or if the optional wildcard SECTION argument is missing, for every orphan input section. An orphan section is one not specifically mentioned in a linker script. You may use this option multiple times on the command line It prevents the normal merging of input sections with the same name, overriding output section assignments in a linker script. Display the version number for ld . The - V option also lists the supported emulations. Other keywords are ignored for Solaris compatibility. --start-group archives --end-group The archives should be a list of archive files. They may be either explicit file names, or - l options. The specified archives are searched repeatedly until no new undefined references are created. Normally, an archive is searched only once in the order that it is specified on the command line. If a symbol in that archive is needed to resolve an undefined symbol referred to by an object in an archive that appears later on the command line, the linker would not be able to resolve that reference. By grouping the archives, they all be searched repeatedly until all possible references are resolved. Using this option has a significant performance cost. It is best to use it only when there are unavoidable circular references between two or more archives. Tells the linker to accept input files whose architecture cannot be recognised. The assumption is that the user knows what they are doing and deliberately wants to link in these unknown input files. This was the default behaviour of the linker, before release 2.14. The default behaviour from release 2.14 onwards is to reject such input files, and so the --accept-unknown-input-arch option has been added to restore the old behaviour. This option affects ELF DTNEEDED tags for dynamic libraries mentioned on the command line after the --as-needed option. Normally the linker will add a DTNEEDED tag for each dynamic library mentioned on the command line, regardless of whether the library is actually needed or not. --as-needed causes a DTNEEDED tag to only be emitted for a library that satisfies an undefined symbol reference from a regular object file or, if the library is not found in the DTNEEDED lists of other libraries linked up to that point, an undefined symbol reference from another dynamic library. --no-as-needed restores the default behaviour. These two options have been deprecated because of the similarity of their names to the --as-needed and --no-as-needed options. They have been replaced by --copy-dt-needed-entries and --no-copy-dt-needed-entries . This option is ignored for SunOS compatibility. Link against dynamic libraries. This is only meaningful on platforms for which shared libraries are supported. This option is normally the default on such platforms. The different variants of this option are for compatibility with various systems. You may use this option multiple times on the command line: it affects library searching for - l options which follow it. Set the DF1GROUP flag in the DTFLAGS1 entry in the dynamic section. This causes the runtime linker to handle lookups in this object and its dependencies to be performed only inside the group. --unresolved-symbolsreport-all is implied. This option is only meaningful on ELF platforms which support shared libraries. Do not link against shared libraries. This is only meaningful on platforms for which shared libraries are supported. The different variants of this option are for compatibility with various systems. You may use this option multiple times on the command line: it affects library searching for - l options which follow it. This option also implies --unresolved-symbolsreport-all . This option can be used with - shared . Doing so means that a shared library is being created but that all of the librarys external references must be resolved by pulling in entries from static libraries. When creating a shared library, bind references to global symbols to the definition within the shared library, if any. Normally, it is possible for a program linked against a shared library to override the definition within the shared library. This option is only meaningful on ELF platforms which support shared libraries. When creating a shared library, bind references to global function symbols to the definition within the shared library, if any. This option is only meaningful on ELF platforms which support shared libraries. Specify the name of a dynamic list file to the linker. This is typically used when creating shared libraries to specify a list of global symbols whose references shouldnt be bound to the definition within the shared library, or creating dynamically linked executables to specify a list of symbols which should be added to the symbol table in the executable. This option is only meaningful on ELF platforms which support shared libraries. The format of the dynamic list is the same as the version node without scope and node name. Include all global data symbols to the dynamic list. Provide the builtin dynamic list for C operator new and delete. It is mainly useful for building shared libstdc. Provide the builtin dynamic list for C runtime type identification. Asks the linker not to check section addresses after they have been assigned to see if there are any overlaps. Normally the linker will perform this check, and if it finds any overlaps it will produce suitable error messages. The linker does know about, and does make allowances for sections in overlays. The default behaviour can be restored by using the command line switch --check-sections . Section overlap is not usually checked for relocatable links. You can force checking in that case by using the --check-sections option. This option affects the treatment of dynamic libraries referred to by DTNEEDED tags inside ELF dynamic libraries mentioned on the command line. Normally the linker wont add a DTNEEDED tag to the output binary for each library mentioned in a DTNEEDED tag in an input dynamic library. With --copy-dt-needed-entries specified on the command line however any dynamic libraries that follow it will have their DTNEEDED entries added. The default behaviour can be restored with --no-copy-dt-needed-entries . This option also has an effect on the resolution of symbols in dynamic libraries. With --copy-dt-needed-entries dynamic libraries mentioned on the command line will be recursively searched, following their DTNEEDED tags to other libraries, in order to resolve symbols required by the output binary. With the default setting however the searching of dynamic libraries that follow it will stop with the dynamic library itself. No DTNEEDED links will be traversed to resolve symbols. Output a cross reference table. If a linker map file is being generated, the cross reference table is printed to the map file. Otherwise, it is printed on the standard output. The format of the table is intentionally simple, so that it may be easily processed by a script if necessary. The symbols are printed out, sorted by name. For each symbol, a list of file names is given. If the symbol is defined, the first file listed is the location of the definition. The remaining files contain references to the symbol. This option inhibits the assignment of addresses to common symbols. The script command INHIBITCOMMONALLOCATION has the same effect. The --no-define-common option allows decoupling the decision to assign addresses to Common symbols from the choice of the output file type otherwise a non-Relocatable output type forces assigning addresses to Common symbols. Using --no-define-common allows Common symbols that are referenced from a shared library to be assigned addresses only in the main program. This eliminates the unused duplicate space in the shared library, and also prevents any possible confusion over resolving to the wrong duplicate when there are many dynamic modules with specialized search paths for runtime symbol resolution. Create a global symbol in the output file, containing the absolute address given by expression . You may use this option as many times as necessary to define multiple symbols in the command line. A limited form of arithmetic is supported for the expression in this context: you may give a hexadecimal constant or the name of an existing symbol, or use and - to add or subtract hexadecimal constants or symbols. If you need more elaborate expressions, consider using the linker command language from a script. Note: there should be no white space between symbol, the equals sign ( ), and expression . These options control whether to demangle symbol names in error messages and other output. When the linker is told to demangle, it tries to present symbol names in a readable fashion: it strips leading underscores if they are used by the object file format, and converts C mangled symbol names into user readable names. Different compilers have different mangling styles. The optional demangling style argument can be used to choose an appropriate demangling style for your compiler. The linker will demangle by default unless the environment variable COLLECTNODEMANGLE is set. These options may be used to override the default. Set the name of the dynamic linker. This is only meaningful when generating dynamically linked ELF executables. The default dynamic linker is normally correct dont use this unless you know what you are doing. Treat all warnings as errors. The default behaviour can be restored with the option --no-fatal-warnings . Make sure that an output file has a. exe suffix. If a successfully built fully linked output file does not have a. exe or. dll suffix, this option forces the linker to copy the output file to one of the same name with a. exe suffix. This option is useful when using unmodified Unix makefiles on a Microsoft Windows host, since some versions of Windows wont run an image unless it ends in a. exe suffix. Enable garbage collection of unused input sections. It is ignored on targets that do not support this option. The default behaviour (of not performing this garbage collection) can be restored by specifying --no-gc-sections on the command line. --gc-sections decides which input sections are used by examining symbols and relocations. The section containing the entry symbol and all sections containing symbols undefined on the command-line will be kept, as will sections containing symbols referenced by dynamic objects. Note that when building shared libraries, the linker must assume that any visible symbol is referenced. Once this initial set of sections has been determined, the linker recursively marks as used any section referenced by their relocations. See --entry and --undefined . This option can be set when doing a partial link (enabled with option - r ). In this case the root of symbols kept must be explicitly specified either by an --entry or --undefined option or by a ENTRY command in the linker script. List all sections removed by garbage collection. The listing is printed on stderr. This option is only effective if garbage collection has been enabled via the --gc-sections ) option. The default behaviour (of not listing the sections that are removed) can be restored by specifying --no-print-gc-sections on the command line. Print the name of the default output format (perhaps influenced by other command-line options). This is the string that would appear in an OUTPUTFORMAT linker script command. Print a summary of the command-line options on the standard output and exit. Report unresolved symbols that are contained in shared libraries, but ignore them if they come from regular object files. Report unresolved symbols that come from regular object files, but ignore them if they come from shared libraries. This can be useful when creating a dynamic binary and it is known that all the shared libraries that it should be referencing are included on the linkers command line. The behaviour for shared libraries on their own can also be controlled by the -- no - allow-shlib-undefined option. Normally the linker will generate an error message for each reported unresolved symbol but the option --warn-unresolved-symbols can change this to a warning. Display the version number for ld and list the linker emulations supported. Display which input files can and cannot be opened. Display the linker script being used by the linker. If the optional NUMBER argument gt 1 . plugin symbol status will also be displayed. Specify the name of a version script to the linker. This is typically used when creating shared libraries to specify additional information about the version hierarchy for the library being created. This option is only fully supported on ELF platforms which support shared libraries. It is partially supported on PE platforms, which can use version scripts to filter symbol visibility in auto-export mode: any symbols marked local in the version script will not be exported. Warn when a common symbol is combined with another common symbol or with a symbol definition. Unix linkers allow this somewhat sloppy practice, but linkers on some other operating systems do not. This option allows you to find potential problems from combining global symbols. Unfortunately, some C libraries use this practice, so you may get some warnings about symbols in the libraries as well as in your programs. There are three kinds of global symbols, illustrated here by C examples: A definition, which goes in the initialized data section of the output file. An undefined reference, which does not allocate space. There must be either a definition or a common symbol for the variable somewhere. A common symbol. If there are only (one or more) common symbols for a variable, it goes in the uninitialized data area of the output file. The linker merges multiple common symbols for the same variable into a single symbol. If they are of different sizes, it picks the largest size. The linker turns a common symbol into a declaration, if there is a definition of the same variable. The --warn-common option can produce five kinds of warnings. Each warning consists of a pair of lines: the first describes the symbol just encountered, and the second describes the previous symbol encountered with the same name. One or both of the two symbols will be a common symbol. 1. Turning a common symbol into a reference, because there is already a definition for the symbol. 2. Turning a common symbol into a reference, because a later definition for the symbol is encountered. This is the same as the previous case, except that the symbols are encountered in a different order. 3. Merging a common symbol with a previous same-sized common symbol. 4. Merging a common symbol with a previous larger common symbol. 5. Merging a common symbol with a previous smaller common symbol. This is the same as the previous case, except that the symbols are encountered in a different order. Warn if any global constructors are used. This is only useful for a few object file formats. For formats like COFF or ELF, the linker can not detect the use of global constructors. Warn if multiple global pointer values are required in the output file. This is only meaningful for certain processors, such as the DEC Alpha. Specifically, some processors put large-valued constants in a special section. A special register (the global pointer) points into the middle of this section, so that constants can be loaded efficiently via a base-register relative addressing mode. Since the offset in base-register relative mode is fixed and relatively small (e. g. 16 bits ), this limits the maximum size of the constant pool. Thus, in large programs, it is often necessary to use multiple global pointer values in order to be able to address all possible constants. This option causes a warning to be issued whenever this case occurs. Only warn once for each undefined symbol, rather than once per module which refers to it. Warn if the address of an output section is changed because of alignment. Typically, the alignment will be set by an input section. The address will only be changed if it not explicitly specified that is, if the SECTIONS command does not specify a start address for the section. Warn if the linker adds a DTTEXTREL to a shared object.
No comments:
Post a Comment