Thursday 24 August 2017

Ld Format Binär Optionen


Hat jemand eine Idee, wie man jede Ressource-Datei direkt in die ausführbare Datei oder die freigegebene Bibliotheksdatei mithilfe von GCC kompilieren kann. Beispielsweise können Sie Bilddateien hinzufügen, die sich nie ändern (und wenn sie das tun müssen, muss die ID trotzdem ersetzt werden) und würde nicht wollen Sie liegen im Dateisystem herum. Wenn dies möglich ist (und ich denke, es ist, weil Visual C für Windows dies auch tun kann), wie kann ich die Dateien laden, die in der eigenen Binärdatei gespeichert sind. Ist die ausführbare Parse selbst, finden Sie die Datei und extrahieren Sie die Daten aus Es ist vielleicht eine Option für GCC, die ich noch nicht gesehen habe. Mit Suchmaschinen nicht wirklich spucken die richtige Sachen. Ich brauche das, um für geteilte Bibliotheken und normale ELF-ausführbare Dateien zu arbeiten. Jede Hilfe wird geschätzt Gibt so etwas wie: Für die Kompatibilität mit anderen Code können Sie dann entweder fmemopen verwenden, um ein normales FILE-Objekt zu erhalten, oder alternativ std :: stringstream, um einen iostream zu machen. Std :: stringstream ist nicht toll für diese aber und Sie können natürlich nur einen Zeiger überall verwenden, wo Sie einen Iterator verwenden können. Wenn Sie dies mit automake vergessen, vergessen Sie nicht, BUILTSOURCES entsprechend einzustellen. Die schöne Sache, dies zu tun, ist so: Du bekommst Text aus, also kann es in der Versionskontrolle und Patches sinnvoll sein. Es ist tragbar und gut definiert auf jeder Plattform beantwortet Feb 1 11 um 16:04 Update Ich bin gewachsen, um die Kontrolle zu bevorzugen John Ripleys Montage. incbin basierte Lösung bietet und nun eine Variante dazu verwenden. Ich habe objcopy (GNU binutils) verwendet, um die Binärdaten aus einer Datei foo-data. bin in den Datenabschnitt der ausführbaren Datei zu verknüpfen: Das gibt dir eine foo-data. o Objektdatei, die du in deine ausführbare Datei verknüpfen kannst. Die C-Schnittstelle sieht so aus, wie Sie es tun können, wenn Sie Ihre Zielarchitektur mit speziellen Beschränkungen versehen haben, wo konstante und variable Daten gespeichert sind, oder Sie diese Daten im. text-Segment speichern möchten, damit sie in denselben Speichertyp passen Als Programmcode kannst du mit den objcopy-Parametern noch mehr spielen. Antwortete Feb 1 11 um 16:36 gute Idee In meinem Fall it39s nicht sehr nützlich. Aber das ist etwas, das ich in meine Snippet-Kollektion bringen werde. Vielen Dank für das Teilen dieser ndash Atmocreations Feb 1 11 um 18:04 It39s ein bisschen einfacher zu verwenden ld als das Ausgabeformat ist impliziert dort, siehe stackoverflowa4158997201725. Ndash Jan Hudec Mar 11 14 at 18:40 Du kannst Binärdateien mit ld Linker in ausführbare Dateien einbetten. Zum Beispiel, wenn Sie Datei foo. bar haben, dann können Sie es in ausführbare Datei einbetten hinzufügen die folgenden Befehle zu ld Wenn Sie aufrufen ld thru gcc dann müssen Sie hinzufügen - Wl Here - Formatbinary sagt dem Linker, dass die folgende Datei ist Binär - und --formatdefault schaltet wieder auf das Standard-Eingabeformat zurück (dies ist sinnvoll, wenn Sie weitere Eingabedateien nach foo. bar angeben). Dann kannst du auf den Inhalt deiner Datei aus dem Code zugreifen: Es gibt auch das Symbol namens binaryfoobarsize. Ich denke, es ist von Typ uintptrt aber ich habe es nicht überprüft. Ich hatte vor kurzem die Notwendigkeit, eine Datei in eine ausführbare Datei einzubetten. Da ich bei der Kommandozeile mit gcc, et al und nicht mit einem ausgefallenen RAD-Tool arbeite, das alles perfekt macht, war es mir nicht sofort klar, wie man das macht. Ein bisschen auf der Suche nach dem Netz fand einen Hack, um es im Grunde auf das Ende der ausführbaren Datei zu katzen und dann zu entschlüsseln, wo es auf einer Reihe von Informationen basierte, die ich nicht wissen wollte. Scheint, wie sollte es ein besserer Weg sein. Und es ist, seine objcopy zur Rettung. Objcopy konvertiert Objektdateien oder ausführbare Dateien von einem Format in ein anderes. Eines der Formate, die es versteht, ist binär, was im Grunde jede Datei ist, die nicht in einem der anderen Formate ist, die es versteht. Also hast du wohl die Idee vorgestellt, die Datei zu konvertieren, die wir in eine Objektdatei einbetten wollen, dann kann man einfach mit dem Rest unseres Codes verknüpfen. Lasst uns sagen, wir haben einen Dateinamen data. txt, den wir in unsere ausführbare Datei einbetten wollen: Um dies in eine Objektdatei zu konvertieren, die wir mit unserem Programm verknüpfen können, verwenden wir einfach objcopy, um eine. o-Datei zu produzieren: Das sagt, dass unsere Eingabe Datei ist im Binärformat, dass unsere Ausgabedatei im Format elf32-i386 (Objektdateien auf dem x86) sein sollte. Die Option - Binary-Architecture gibt an, ob die Ausgabedatei auf einem x86 ausgeführt werden soll. Dies wird benötigt, damit ld die Datei für die Verknüpfung mit anderen Dateien für die x86 akzeptieren wird. Man würde denken, dass die Angabe des Ausgabeformats als elf32-i386 das bedeuten würde, aber das geht nicht. Nun, da wir eine Objektdatei haben, müssen wir sie nur noch einbinden, wenn wir den Linker ausführen: Wenn wir das Ergebnis ausführen, bekommen wir das Gebet für die Ausgabe: Natürlich habe ich die ganze Geschichte noch nicht erzählt Wenn objcopy die obige Konvertierung macht, fügt man der umgewandelten Objektdatei einige Linkersymbole hinzu: Nach der Verknüpfung geben diese Symbole den Anfang und das Ende der eingebetteten Datei an. Die Symbolnamen werden durch Voranstellen von Binär und Hinzufügen von Anfang oder Ende des Dateinamens gebildet. Wenn der Dateiname alle Zeichen enthält, die in einem Symbolnamen ungültig sind, werden sie in Unterstriche umgewandelt (zB data. txt wird datatxt). Wenn du bei der Verknüpfung mit diesen Symbolen ungelöste Namen bekommst, mach ein Hexdump - C auf die Objektdatei und sieh dir das Ende des Dumps für die Namen an, die objcopy gewählt haben. Der Code, um die eingebettete Datei tatsächlich zu benutzen, sollte nun vernünftigerweise offensichtlich sein: Eine wichtige und subtile Sache zu beachten ist, dass die Symbole zu den Objektdatei arent Variablen hinzugefügt werden. Sie enthalten keine Daten, sondern ihre Adresse ist ihr Wert. Ich erkläre sie als Typ char, weil es für dieses Beispiel bequem ist: die eingebetteten Daten sind Zeichendaten. Allerdings könntest du sie als irgendetwas deklarieren, da int, wenn die Daten ein Array von ganzen Zahlen sind, oder als struct foobart, wenn die Daten irgendeine Reihe von foo Bars waren. Wenn die eingebetteten Daten nicht einheitlich sind, dann ist char wahrscheinlich die bequemste: nehmen Sie ihre Adresse und werfen Sie den Zeiger auf den richtigen Typ, wie Sie die Daten durchqueren. Beantwortet Apr 1 11 bei 20: 39Linux und Unix ld Befehl ld kombiniert eine Anzahl von Objekt - und Archivdateien, verlagert ihre Daten und verbindet Symbolreferenzen. Normalerweise ist der letzte Schritt bei der Erstellung eines Programms zu laufen ld. Ld akzeptiert Linker-Befehls-Sprachdateien, die in einer Superset von ATampT s Link Editor-Befehlssyntax geschrieben sind, um eine explizite und vollständige Kontrolle über den Verknüpfungsprozess zu liefern. Für ausführliche Details zur ld-Befehlssprache siehe die ld-Info-Seite. Hier finden Sie einen umfassenden Überblick über die Verwendung von GNU ld, die in den meisten Linux-Versionen verwendet wird. Diese Version von ld verwendet die Allzweck-BFD-Bibliotheken, um auf Objektdateien zu arbeiten. Dies erlaubt es ld, Objektdateien in vielen verschiedenen Formaten zu lesen, zu kombinieren und zu schreiben: zB COFF oder a. out. Verschiedene Formate können miteinander verknüpft werden, um jede verfügbare Art von Objektdatei zu erzeugen. Abgesehen von seiner Flexibilität ist der GNU-Linker hilfreicher als andere Linker bei der Bereitstellung von Diagnoseinformationen. Viele Linker verlassen die Ausführung sofort, wenn sie einen Fehler aufgetreten, wann immer möglich, ld fortsetzt die Ausführung, so dass Sie andere Fehler identifizieren können (oder in manchen Fällen eine Ausgabedatei trotz des Fehlers zu erhalten). Der GNU Linker ld soll eine breite Palette von Situationen abdecken und möglichst kompatibel mit anderen Linkern sein. Als Ergebnis haben Sie viele Möglichkeiten, um sein Verhalten zu kontrollieren. Der Linker unterstützt viele Befehlszeilenoptionen, aber in der Praxis werden nur wenige von ihnen in einem bestimmten Kontext verwendet. Zum Beispiel ist eine häufige Verwendung von ld, um Standard-Unix-Objektdateien auf einem standardisierten, unterstützten Unix-System zu verknüpfen. Auf solch einem System, um eine Datei zu verbinden hello. o: Dies sagt ld, um eine Datei namens Ausgabe als Ergebnis der Verknüpfung der Datei libcrt0.o mit hello. o und die Bibliothek libc. a, die aus der Standard-Suche kommen zu produzieren Verzeichnisse Siehe unten die Option - l. Einige der Befehlszeilenoptionen zu ld können an jedem beliebigen Punkt in der Befehlszeile angegeben werden. Optionen, die sich auf Dateien beziehen, wie zB - l oder - T. Dass die Datei an dem Punkt gelesen wird, an dem die Option in der Befehlszeile angezeigt wird, relativ zu den Objektdateien und anderen Dateiauswahl. Das Wiederholen von Nicht-Datei-Optionen mit einem anderen Argument hat entweder keinen weiteren Effekt oder überschreibt vorherige Vorkommnisse (die weiter links auf der Befehlszeile) dieser Option. Optionen, die in mehrfacher Hinsicht sinnvoll angegeben werden können, sind in den nachfolgenden Beschreibungen aufgeführt. Nicht-Option-Argumente sind Objektdateien oder Archive, die miteinander verknüpft werden sollen. Sie können folgen, vorgehen oder mit Befehlszeilenoptionen gemischt werden, außer dass ein Objektdatei-Argument nicht zwischen einer Option und seinem Argument platziert werden kann. Normalerweise wird der Linker mit mindestens einer Objektdatei aufgerufen, aber Sie können andere Formen von binären Eingabedateien mit - l angeben. - R. Und die Skriptbefehlssprache. Wenn keine binären Eingabedateien angegeben sind, erzeugt der Linker keine Ausgabe und gibt die Nachricht keine Eingabedateien aus. Wenn der Linker das Format einer Objektdatei nicht erkennen kann, wird davon ausgegangen, dass es sich um ein Linkerskript handelt. Ein auf diese Weise spezifiziertes Skript erweitert das für den Link verwendete Haupt-Linkerskript (entweder das Standard-Linkerskript oder das mit "T" angegebene). Diese Funktion erlaubt es dem Linker, sich gegen eine Datei zu verweisen, die ein Objekt oder ein Archiv zu sein scheint. Aber eigentlich nur einige Symbolwerte definiert oder nutzt INPUT oder GROUP, um andere Objekte zu laden. Die Angabe eines Skripts auf diese Weise ergänzt lediglich das Haupt-Linker-Skript, wobei die zusätzlichen Befehle nach dem Hauptskript die Option - T verwenden, um das Standard-Linkerskript vollständig zu ersetzen, aber den Effekt des INSERT-Befehls zu beachten. Bei Optionen, deren Namen ein einziger Buchstabe sind, müssen Options-Argumente entweder dem Options-Buchstaben folgen, ohne dazwischen zu platzieren. Oder unmittelbar nach der Option, die sie verlangt, als gesonderte Argumente gegeben werden. Für Optionen, deren Namen mehrere Buchstaben sind, können entweder ein Bindestrich oder zwei dem Optionsnamen vorangestellt werden. - trace-symbol und --trace-symbol sind gleichwertig. Beachten Sie, dass es eine Ausnahme von dieser Regel gibt: Mehrere Buchstaben-Optionen, die mit einem Kleinbuchstaben beginnen o können nur zwei Bindestrichen vorangestellt werden. Dies ist die Verwechslung mit der Option - o zu reduzieren. Also - omagic setzt den Ausgabedateinamen auf Magie, während --omagic das NMAGIC-Flag auf den Ausgang setzt. Argumente für mehrere Buchstaben-Optionen müssen entweder von dem Optionsnamen durch ein Gleichheitszeichen getrennt sein oder als separate Argumente unmittelbar nach der Option angegeben werden, die sie benötigt. Zum Beispiel sind --trace-symbol foo und --trace-symbolfoo äquivalent. Einzigartige Abkürzungen der Namen von Mehrfachbuchstaben werden akzeptiert. Beachten Sie, dass, wenn der Linker indirekt über einen Compiler-Treiber (z. B. gcc) aufgerufen wird, dann alle Linker-Befehlszeilenoptionen von - Wl vorangestellt werden sollen. (Oder was auch immer für den jeweiligen Compiler-Treiber geeignet ist) wie folgt: Das ist wichtig, denn sonst kann das Compiler-Treiber-Programm die Linker-Optionen leise fallen lassen, was zu einem schlechten Link führt. Verwirrung kann auch auftreten, wenn Sie Optionen übergeben, die Werte über einen Treiber erfordern, da die Verwendung eines Leerzeichens zwischen Option und Argument als Trennzeichen fungiert und dem Fahrer veranlasst, nur die Option an den Linker und das Argument an den Compiler weiterzugeben. In diesem Fall ist es am einfachsten, die zusammenhängenden Formen von Einzel - und Mehrfachbuchstaben zu verwenden, wie zB: Hier ist eine Tabelle der generischen Befehlszeilenschalter, die vom GNU-Linker akzeptiert werden: Lesen Sie Befehlszeilenoptionen aus Datei. Die gelesenen Optionen werden anstelle der ursprünglichen Dateiauswahl eingefügt. Wenn Datei nicht existiert oder nicht gelesen werden kann, dann wird die Option wörtlich behandelt und nicht entfernt. Optionen in der Datei sind durch Leerzeichen getrennt. Ein Whitespace-Charakter kann in einer Option enthalten sein, indem er die gesamte Option entweder in Einzel - oder Doppel-Anführungszeichen umgibt. Jedes Zeichen (einschließlich eines Backslash) kann durch Präfixieren des Zeichens mit einem Backslash enthalten sein. Die Datei kann selbst zusätzliche Dateioptionen enthalten. Diese Optionen werden rekursiv verarbeitet. Diese Option wird für die HP-UX-Kompatibilität unterstützt. Das Keyword-Argument muss eines der Strings-Archiv sein. Geteilt Oder Standard. - Aarchiv ist funktional gleichbedeutend mit - Bstatic. Und die beiden anderen Schlüsselwörter funktionieren gleichbedeutend mit - Bdynamic. Diese Option kann beliebig oft verwendet werden. Fügt dem DTAUDIT-Eintrag des dynamischen Abschnitts AUDITLIB hinzu. AUDITLIB wird nicht auf Existenz geprüft, noch wird es das in der Bibliothek angegebene DTSONAME verwenden. Wenn mehrfach spezifiziert, enthält DTAUDIT eine Doppelpunkt-getrennte Liste der zu verwendenden Audit-Schnittstellen. Wenn der Linker bei der Suche nach gemeinsam genutzten Bibliotheken ein Objekt mit einem Audit-Eintrag findet, wird er in der Ausgabedatei einen entsprechenden DTDEPAUDIT-Eintrag hinzufügen. Diese Option ist nur auf ELF-Plattformen sinnvoll, die die rtld-audit-Schnittstelle unterstützen. In der aktuellen Version von ld. Diese Option ist nur für die Intel 960-Architekturarchitektur sinnvoll. In dieser ld-Konfiguration identifiziert das Architekturargument die jeweilige Architektur in der 960-Familie und ermöglicht einige Sicherungen und die Änderung des Archivbibliotheks-Suchpfades. Zukünftige Releases von ld können ähnliche Funktionalität für andere Architekturfamilien unterstützen. Ld kann so konfiguriert werden, dass es mehr als eine Art von Objektdatei unterstützt. Wenn Ihr ld auf diese Weise konfiguriert ist, können Sie mit der Option - b das Binärformat für Eingabeobjektdateien angeben, die dieser Option auf der Befehlszeile folgen. Auch wenn ld konfiguriert ist, um alternative Objektformate zu unterstützen, müssen Sie dies normalerweise nicht angeben, da ld so konfiguriert werden sollte, dass es als Standard-Eingabeformat das üblichste Format auf jeder Maschine erwartet. Eingabeformat ist ein Textstring, der Name eines bestimmten Formats, das von den BFD-Bibliotheken unterstützt wird. Sie können die verfügbaren Binärformate mit objdump - i auflisten. Sie können diese Option verwenden, wenn Sie Dateien mit einem ungewöhnlichen Binärformat verknüpfen. Sie können auch - b verwenden, um Formate explizit zu wechseln (bei der Verknüpfung von Objektdateien verschiedener Formate), indem sie - b Eingabeformat vor jeder Gruppe von Objektdateien in einem bestimmten Format enthalten. Das Standardformat wird aus der Umgebungsvariable GNUTARGET übernommen. Sie können auch das Eingabeformat aus einem Skript mit dem Befehl TARGET definieren. Für die Kompatibilität mit Linkern, die von MRI produziert werden, akzeptiert ld Skriptdateien, die in einer alternativen, eingeschränkten Befehlssprache geschrieben sind und im Abschnitt MRI Compatible Script Files der GNU ld Dokumentation beschrieben sind. Führen Sie MRI-Skriptdateien mit der Option - c ein. Verwenden Sie die Option - T, um Linkerskripts auszuführen, die in der allgemeinen ld-Skriptsprache geschrieben sind. Wenn MRI-cmdfile nicht existiert, sucht ld es in den Verzeichnissen, die durch irgendwelche Optionen - L angegeben werden. Diese drei Optionen sind gleichwertig mehrere Formen werden für die Kompatibilität mit anderen Linkern unterstützt. Sie weisen den üblichen Symbolen Platz zu, auch wenn eine umsetzbare Ausgabedatei angegeben ist (mit - r). Der Skriptbefehl FORCECOMMONALLOCATION hat die gleiche Wirkung. Fügt dem DTDEPAUDIT-Eintrag des dynamischen Abschnitts AUDITLIB hinzu. AUDITLIB wird nicht auf Existenz geprüft, noch wird es das in der Bibliothek angegebene DTSONAME verwenden. Wenn mehrfach angegeben, enthält DTDEPAUDIT eine durch Doppelpunkt getrennte Liste der zu verwendenden Audit-Schnittstellen. Diese Option ist nur auf ELF-Plattformen sinnvoll, die die rtld-audit-Schnittstelle unterstützen. Die Option - P ist für die Solaris-Kompatibilität vorgesehen. Verwenden Sie den Eintrag als explizites Symbol für die Ausführung des Programms und nicht für den Standardeintrag. Wenn es kein Symbol namens Eintrag gibt. Wird der Linker versuchen, die Eingabe als Zahl zu analysieren und diese als die Eintragsadresse zu verwenden (die Nummer wird in der Basis 10 interpretiert. Sie können eine führende 0x für Basis 16 oder eine führende 0 für Basis 8 verwenden). Gibt eine Liste von Archivbibliotheken an, aus denen Symbole nicht automatisch exportiert werden sollen. Die Bibliotheksnamen können durch Kommas oder Doppelpunkte abgegrenzt werden. Angabe --exclude-libs ALL schließt Symbole in allen Archivbibliotheken aus dem automatischen Export aus. Diese Option ist nur für den i386 PE-Port des Linkers und für ELF-gezielte Ports verfügbar. Für i386 PE werden Symbole, die explizit in einer. def-Datei aufgeführt sind, immer noch exportiert, unabhängig von dieser Option. Für ELF-zielgerichtete Ports werden die von dieser Option betroffenen Symbole als versteckt behandelt. Gibt eine Liste von Objektdateien oder Archivmitgliedern an, von denen Symbole nicht automatisch exportiert werden sollen, sondern die Großhandels in die Importbibliothek kopiert werden sollen, die während des Links erzeugt wird. Die Modulnamen können durch Kommas oder Doppelpunkte abgegrenzt werden und müssen genau mit den Dateinamen übereinstimmen, die von ld verwendet werden, um die Dateien für Archivmitglieder zu öffnen. Dies ist einfach der Mitgliedsname, aber für Objektdateien muss der angegebene Name genau einen beliebigen Pfad enthalten und entsprechen Um die Eingabedatei auf der Linkers-Befehlszeile anzugeben. Diese Option ist nur für den i386 PE-Port des Linkers verfügbar. In einer. def-Datei explizit aufgelistete Symbole werden immer noch exportiert, unabhängig von dieser Option. Wenn Sie eine dynamisch verknüpfte ausführbare Datei erstellen, wird mit der Option - E oder der Option --export-dynamic der Linker alle Symbole zur dynamischen Symboltabelle hinzugefügt. Die dynamische Symboltabelle ist der Satz von Symbolen, die zur Laufzeit aus dynamischen Objekten sichtbar sind. Wenn Sie keine dieser Optionen verwenden (oder die Option --no-export-dynamic verwenden, um das Standardverhalten wiederherzustellen), enthält die dynamische Symboltabelle normalerweise nur die Symbole, auf die von einem dynamischen Objekt verwiesen wird, das im Link erwähnt wird. Wenn Sie dlopen verwenden, um ein dynamisches Objekt zu laden, das auf die vom Programm definierten Symbole und nicht auf ein anderes dynamisches Objekt zurückgreifen muss, müssen Sie diese Option wahrscheinlich bei der Verknüpfung des Programms verwenden. Sie können auch die dynamische Liste verwenden, um zu steuern, welche Symbole der dynamischen Symboltabelle hinzugefügt werden sollen, wenn das Ausgabeformat es unterstützt. Siehe Beschreibung der --dynamischen Liste. Beachten Sie, dass diese Option für ELF-gezielte Ports spezifisch ist. PE-Ziele unterstützen eine ähnliche Funktion, um alle Symbole aus einer DLL oder EXE zu exportieren, siehe die Beschreibung von --export-all-Symbole unten. Link big-endian Objekte. Dies wirkt sich auf das Standardausgabeformat aus. Link-Little-Endian-Objekte. Dies wirkt sich auf das Standardausgabeformat aus. Wenn Sie ein ELF-Freigabeobjekt erstellen, legen Sie das interne Feld DTAUXILIARY auf den angegebenen Namen ein. Dies teilt dem dynamischen Linker mit, dass die Symboltabelle des gemeinsamen Objekts als Hilfsfilter auf der Symboltabelle des gemeinsamen Objektnamens verwendet werden soll. Wenn Sie später ein Programm mit diesem Filterobjekt verknüpfen, dann, wenn Sie das Programm ausführen, wird der dynamische Linker das Feld DTAUXILIARY sehen. Wenn der dynamische Linker alle Symbole aus dem Filterobjekt auflöst, prüft es zunächst, ob es eine Definition im gemeinsamen Objektnamen gibt. Wenn es eins gibt, wird es anstelle der Definition im Filterobjekt verwendet. Der freigegebene Objektname muss nicht existieren. So kann der freigegebene Objektname verwendet werden, um eine alternative Implementierung bestimmter Funktionen zur Verfügung zu stellen, vielleicht zum Debuggen oder zur maschinenspezifischen Leistung. Diese Option kann mehrmals angegeben werden. Die Einträge DTAUXILIARY werden in der Reihenfolge angelegt, in der sie auf der Kommandozeile erscheinen. Wenn Sie ein gemeinsames ELF-Objekt erstellen, legen Sie das interne DTFILTER-Feld auf den angegebenen Namen ein. Dies teilt dem dynamischen Linker mit, dass die Symboltabelle des freigegebenen Objekts, das erstellt wird, als Filter auf der Symboltabelle des gemeinsamen Objektnamens verwendet werden soll. Wenn Sie später ein Programm mit diesem Filterobjekt verknüpfen, dann, wenn Sie das Programm ausführen, wird der dynamische Linker das DTFILTER-Feld sehen. Der dynamische Linker löst Symbole entsprechend der Symboltabelle des Filterobjekts wie gewohnt auf, aber es wird tatsächlich mit den Definitionen verknüpft, die im gemeinsamen Objektnamen gefunden wurden. So kann das Filterobjekt verwendet werden, um eine Teilmenge der vom Objektnamen bereitgestellten Symbole auszuwählen. Einige ältere Linker verwendeten die Option - F während einer Kompilierungs-Toolchain zum Spezifizieren des Objekt-Dateiformats für Eingabe - und Ausgabeobjektdateien. Der GNU-Linker verwendet dazu andere Mechanismen: die - b. - formatieren --Oformatoptionen, den TARGET-Befehl in Linkerskripts und die Umgebungsvariable GNUTARGET. Der GNU-Linker ignoriert die Option - F, wenn kein ELF-Freigabeobjekt erstellt wird. Wenn Sie ein ELF-ausführbares oder gemeinsames Objekt erstellen, rufen Sie NAME auf, wenn das ausführbare oder freigegebene Objekt entladen wird, indem Sie DTFINI auf die Adresse der Funktion setzen. Standardmäßig verwendet der Linker fini als Funktion zum Aufruf. Ignoriert Für die Kompatibilität mit anderen Werkzeugen vorgesehen. Legen Sie die maximale Größe der zu optimierenden Objekte mit dem GP-Register auf Größe fest. Dies ist nur sinnvoll für Objektdateiformate wie MIPS ECOFF, die das Setzen von großen und kleinen Objekten in verschiedene Abschnitte unterstützt. Dies wird für andere Objektdateiformate ignoriert. Wenn Sie ein gemeinsames ELF-Objekt erstellen, legen Sie das interne DTSONAME-Feld auf den angegebenen Namen ein. Wenn eine ausführbare Datei mit einem freigegebenen Objekt verknüpft ist, das über ein DTSONAME-Feld verfügt, wird dann, wenn die ausführbare Datei ausgeführt wird, der dynamische Linker versucht, das vom DTSONAME-Feld angegebene freigegebene Objekt zu laden, anstatt mit dem Dateinamen, der dem Linker gegeben wird. Führen Sie einen inkrementellen Link (wie die Option - r) aus. Wenn Sie ein ELF-ausführbares oder gemeinsames Objekt erstellen, rufen Sie NAME auf, wenn das ausführbare oder freigegebene Objekt geladen wird, indem Sie DTINIT an die Adresse der Funktion setzen. Standardmäßig verwendet der Linker init als Funktion zum Aufruf. Fügen Sie die von namespec angegebene Archiv - oder Objektdatei zur Liste der zu verlinkenden Dateien hinzu. Diese Option kann beliebig oft verwendet werden. Wenn namespec ist das Formular: Dateiname. Ld sucht den Bibliothekspfad für eine Datei namens Dateiname. Andernfalls sucht es den Bibliothekspfad für eine Datei namens lib namespec. a. Bei Systemen, die gemeinsam genutzte Bibliotheken unterstützen, kann ld auch nach anderen Dateien als lib namespec. a suchen. Speziell auf ELF - und SunOS-Systemen sucht ld ein Verzeichnis für eine Bibliothek namens lib namespec. so vor der Suche nach einem namens lib namespec. a. Nach der Konvention gibt eine Erweiterung eine gemeinsame Bibliothek an. Beachten Sie, dass dieses Verhalten nicht gilt für: Dateiname. Die immer eine Datei namens Dateiname spezifiziert. Der Linker sucht nur einmal ein Archiv, an dem Ort, an dem es auf der Kommandozeile angegeben ist. Wenn das Archiv ein Symbol definiert, das in einem Objekt, das vor dem Archiv auf der Kommandozeile auftauchte, undefinierte, enthält der Linker die entsprechenden Datei (en) aus dem Archiv. Jedoch wird ein undefiniertes Symbol in einem Objekt, das später auf der Befehlszeile erscheint, nicht dazu führen, dass der Linker das Archiv erneut durchsucht. Sehen Sie die - (Option für einen Weg, um den Linker zu zwingen, Archive mehrmals zu durchsuchen. Sie können das gleiche Archiv mehrmals auf der Kommandozeile auflisten. Diese Art der Archivsuche ist Standard für Unix-Linker. Allerdings, wenn Sie mit ld auf AIX. Beachten Sie, dass es sich von dem Verhalten des AIX-Linkers unterscheidet. Fügen Sie Pfad searchdir zu der Liste der Pfade, die ld sucht nach Archivbibliotheken und ld-Steuerskripts. Sie können diese Option beliebig oft verwenden. Die Verzeichnisse werden durchsucht Die Reihenfolge, in der sie auf der Kommandozeile angegeben sind, Verzeichnisse, die auf der Befehlszeile angegeben sind, werden vor den Standardverzeichnissen durchsucht. Alle Optionen - L gelten für alle Optionen - l, unabhängig von der Reihenfolge, in der die Optionen angezeigt werden Nicht beeinflussen, wie ld nach einem Linker-Skript sucht, es sei denn, die Option - T ist spezifiziert, wenn searchdir beginnt, dann wird das durch das Sysroot-Präfix ersetzt, ein Pfad, der angegeben wird, wenn der Linker konfiguriert ist. Der Standardsatz der gesuchten Pfade (ohne angegeben Mit - L) hängt davon ab, welcher Emulationsmodus ld verwendet wird, und in einigen Fällen auch darüber, wie es zur Bauzeit konfiguriert wurde. Die Pfade können auch in einem Link-Skript mit dem Befehl SEARCHDIR angegeben werden. Verzeichnisse, die auf diese Weise angegeben sind, werden an dem Punkt gesucht, an dem das Linkerskript in der Befehlszeile angezeigt wird. Emulieren Sie den Emulationslinker. Sie können die verfügbaren Emulationen mit den Optionen --verbose oder - V auflisten. Wenn die Option - m nicht verwendet wird, wird die Emulation aus der Umgebungsvariablen LDEMULATION übernommen, falls diese definiert ist. Andernfalls hängt die Standardemulation davon ab, wie der Linker konfiguriert wurde. Drucken Sie eine Linkkarte zur Standardausgabe. Eine Link-Map enthält Informationen über den Link, einschließlich der folgenden: Wo Objektdateien in den Speicher abgebildet sind. Wie übliche Symbole zugeordnet sind. Alle Archivmitglieder, die in den Link aufgenommen wurden, mit einer Erwähnung des Symbols, das das Archivmitglied verursacht hat. Die Werte, die den Symbolen zugeordnet sind. Anmerkung: Symbole, deren Werte durch einen Ausdruck berechnet werden, der einen Verweis auf einen vorherigen Wert desselben Symbols beinhaltet, haben möglicherweise kein korrektes Ergebnis in der Link-Map angezeigt. Dies liegt daran, dass der Linker Zwischenergebnisse verwertet und nur den Endwert eines Ausdrucks beibehält. Unter diesen Umständen zeigt der Linker den endgültigen Wert an, der von eckigen Klammern eingeschlossen ist. So wird zum Beispiel ein Linkerskript, das Folgendes enthält: die folgende Ausgabe in der Link-Map erzeugen, wenn die Option - M verwendet wird: Seitenausrichtung von Abschnitten deaktivieren und die Verknüpfung mit freigegebenen Bibliotheken deaktivieren. Wenn das Ausgabeformat Unix-Magic-Nummern unterstützt, markiere die Ausgabe als NMAGIC. Legen Sie die Text - und Datenabschnitte so ein, dass sie lesbar und beschreibbar sind. Außerdem können Sie das Datensegment nicht ausrichten und die Verknüpfung mit freigegebenen Bibliotheken deaktivieren. Wenn das Ausgabeformat Unix-Magic-Nummern unterstützt, markieren Sie die Ausgabe als OMAGIC. Hinweis: Obwohl ein beschreibbarer Textabschnitt für PE-COFF-Ziele erlaubt ist, entspricht er nicht der von Microsoft veröffentlichten Formatspezifikation. Diese Option negiert die meisten Effekte der Option - N. Es legt den Textabschnitt als schreibgeschützt fest und zwingt das Datensegment, auf Seite ausgerichtet zu werden. Hinweis - Diese Option ermöglicht keine Verknüpfung mit freigegebenen Bibliotheken. Verwenden Sie dazu - Bdynamic. Verwenden Sie die Ausgabe als Name für das von ld erzeugte Programm, wenn diese Option nicht angegeben ist, wird standardmäßig der Name a. out verwendet. Der Skriptbefehl OUTPUT kann auch den Namen der Ausgabedatei angeben. Wenn der Pegel ein numerischer Wert größer als Null ld ist, optimiert der Ausgang. Dies kann erheblich länger dauern und sollte daher wohl nur für die endgültige Binärdatei aktiviert werden. Im Moment wirkt sich diese Option nur auf die Generierung der ELF-Bibliothek aus. Zukünftige Releases des Linkers können diese Option mehr nutzen. Auch derzeit gibt es keinen Unterschied in der Linker Verhalten für verschiedene Nicht-Null-Werte dieser Option. Auch dies kann sich mit zukünftigen Releases ändern. Verlassen Sie Umzugsabschnitte und Inhalte in vollständig verknüpften ausführbaren Dateien. Post Link Analyse und Optimierung Tools können diese Informationen benötigen, um korrekte Änderungen der ausführbaren Dateien durchzuführen. Dies führt zu größeren ausführbaren Dateien. Diese Option wird derzeit nur auf ELF-Plattformen unterstützt. Erzwinge die Ausgabedatei mit dynamischen Abschnitten. Diese Option ist spezifisch für VxWorks Ziele. Generieren Sie eine verlagerbare Ausgabe: d. h. eine Ausgabedatei erzeugen, die wiederum als Eingabe für ld dienen kann. Dies wird oft als partielle Verknüpfung bezeichnet. Als Nebeneffekt, in Umgebungen, die Standard-Unix-Magic-Nummern unterstützen, setzt diese Option auch die Zieldaten der Ausgabedatei auf OMAGIC. Wenn diese Option nicht angegeben ist, wird eine absolute Datei erstellt. Beim Verknüpfen von C-Programmen wird diese Option nicht auf Verweise auf Konstruktoren aufgelöst, um dies zu tun, verwenden Sie - Ur. Wenn eine Eingabedatei nicht das gleiche Format wie die Ausgabedatei hat, wird eine partielle Verknüpfung nur unterstützt, wenn diese Eingabedatei keine Verlagerungen enthält. Verschiedene Ausgabeformate können weitere Einschränkungen haben, zum Beispiel einige a. out-basierte Formate unterstützen keine partielle Verknüpfung mit Eingabedateien in anderen Formaten überhaupt. Diese Option macht dasselbe wie - i. Lesen Sie die Symbolnamen und ihre Adressen aus dem Dateinamen. Aber verlagern Sie es nicht oder legen Sie es in die Ausgabe ein. Damit kann Ihre Ausgabedatei symbolisch auf absolute Speicherorte verweisen, die in anderen Programmen definiert sind. Sie können diese Option mehrmals verwenden. Für die Kompatibilität mit anderen ELF-Linkern, wenn die Option - R von einem Verzeichnisnamen und nicht von einem Dateinamen gefolgt wird, wird sie als die Option - rpath behandelt. Weglassen Sie alle Symbolinformationen aus der Ausgabedatei. Verwenden Sie scriptfile als das Linkerskript. Dieses Skript ersetzt das Standard-Linkerskript von ld (anstatt es hinzuzufügen), so dass die Befehlsleiste alles Notwendige angeben muss, um die Ausgabedatei zu beschreiben. Wenn scriptfile im aktuellen Verzeichnis nicht vorhanden ist, sucht ld es in den Verzeichnissen, die von den vorangehenden Optionen - L angegeben wurden. Multiple - T-Optionen akkumulieren. Verwenden Sie scriptfile als Standard-Linkerskript. Diese Option ähnelt der Option --script, außer dass die Verarbeitung des Skripts verzögert wird, bis der Rest der Befehlszeile verarbeitet wurde. Damit können Optionen nach der Option --default-script auf der Befehlszeile platziert werden, um das Verhalten des Linkerskripts zu beeinflussen, was wichtig sein kann, wenn die Linker-Befehlszeile nicht direkt vom Benutzer gesteuert werden kann. (Z. B. weil die Befehlszeile von einem anderen Werkzeug wie z. B. gcc konstruiert wird). Force-Symbol in die Ausgabedatei als ein undefiniertes Symbol eingegeben werden. Dies kann beispielsweise die Verknüpfung zusätzlicher Module aus Standardbibliotheken auslösen. - u kann mit verschiedenen Optionsargumenten wiederholt werden, um zusätzliche undefinierte Symbole einzugeben. Diese Option entspricht dem Befehl EXTERN linker script. Für irgendetwas anderes als C-Programme entspricht diese Option - r. Es erzeugt eine verlagerbare Ausgabe, d. h. eine Ausgabedatei, die wiederum als Eingabe für ld dienen kann. Beim Verknüpfen von C-Programmen, - Ur löst Referenzen auf Konstruktoren, im Gegensatz zu - r. Es funktioniert nicht zu verwenden - Ur auf Dateien, die selbst mit - Ur verbunden waren, sobald die Konstruktortabelle gebaut wurde, kann es nicht hinzugefügt werden. Verwenden Sie nur für den letzten Teillink und - r für die anderen. Erstellt einen separaten Ausgabeabschnitt für jeden Eingabeabschnitt, der mit SECTION übereinstimmt oder wenn das optionale Platzhalter-SECTION-Argument fehlt, für jeden Waiseneingabeabschnitt. Ein Waisenabschnitt ist einer, der nicht ausdrücklich in einem Linkerskript erwähnt wird. Sie können diese Option mehrmals auf der Befehlszeile verwenden. Es verhindert die normale Verschmelzung von Eingabeabschnitten mit demselben Namen und übergeordneten Ausgabebereichszuordnungen in einem Linkerskript. Zeigen Sie die Versionsnummer für ld an. Die Option - V listet auch die unterstützten Emulationen auf. Andere Schlüsselwörter werden für die Kompatibilität von Solaris ignoriert. --Start-Gruppenarchive --end-Gruppe Die Archive sollen eine Liste von Archivdateien sein. Sie können entweder explizite Dateinamen oder - l Optionen sein. Die angegebenen Archive werden wiederholt durchsucht, bis keine neuen undefinierten Referenzen erstellt wurden. Normalerweise wird ein Archiv nur einmal in der Reihenfolge durchsucht, in der es auf der Befehlszeile angegeben ist. Wenn ein Symbol in diesem Archiv benötigt wird, um ein undefiniertes Symbol zu lösen, auf das sich ein Objekt in einem Archiv bezieht, das später auf der Befehlszeile erscheint, kann der Linker diese Referenz nicht auflösen. Durch die Gruppierung der Archive werden alle wiederholt durchsucht, bis alle möglichen Referenzen gelöst sind. Mit dieser Option haben Sie erhebliche Performance-Kosten. Es ist am besten, es nur zu verwenden, wenn es unvermeidliche kreisförmige Referenzen zwischen zwei oder mehr Archiven gibt. Weist dem Linker an, Eingabedateien zu akzeptieren, deren Architektur nicht erkannt werden kann. Die Annahme ist, dass der Benutzer weiß, was sie tun und bewusst will, um in diesen unbekannten Eingabedateien zu verknüpfen. Dies war das Standardverhalten des Linkers, vor 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. 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. Here is a summary of the options you can use on the ld command line: This plethora of command-line options may seem intimidating, 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 discussion of the - l option below.) The command-line options to ld may be specified in any order, and may be repeated at will. Repeating most 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. The exceptions--which may meaningfully be used more than once--are - A. - b (or its synonym - format ), - defsym. - L. - l. - R. - u. and -( (or its synonym --start-group ). The list of object files to be linked together, shown as objfile. may follow, precede, or be mixed in with command-line options, except that an objfile 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 can not 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. See section Command Language. 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, --oformat and - oformat are equivalent. 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, --oformat srec and --oformatsrec are equivalent. Unique abbreviations of the names of multiple-letter options are accepted. - b input-format 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 .) - format input-format has the same effect, as does the script command TARGET. See section BFD. 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 see section Option Commands. - Bstatic Do not link against shared libraries. This is only meaningful on platforms for which shared libraries are supported. - Bdynamic 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. - Bsymbolic 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. - c MRI-commandfile For compatibility with linkers produced by MRI, ld accepts script files written in an alternate, restricted command language, described in section MRI Compatible Script Files. 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. - d - dc - dp 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. See section Option Commands. - defsym symbol expression 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 (see section Assignment: Defining Symbols ). Note: there should be no white space between symbol. the equals sign ( ), and expression. - embedded-relocs This option is only meaningful when linking MIPS embedded PIC code, generated by the - membedded-pic option to the GNU compiler and assembler. Es verursacht den Linker, eine Tabelle zu erstellen, die zur Laufzeit verwendet werden kann, um alle Daten zu verlagern, die statisch auf Zeigerwerte initialisiert wurden. See the code in testsuiteld-empic for details. - e entry Use entry as the explicit symbol for beginning execution of your program, rather than the default entry point. See section The Entry Point. for a discussion of defaults and other ways of specifying the entry point. - F - F format Ignored. Some older linkers used this option throughout a compilation toolchain for specifying object-file format for both input and output object files. The mechanisms ld uses for this purpose (the - b or - format options for input files, - oformat option or the TARGET command in linker scripts for output files, the GNUTARGET environment variable) are more flexible, but ld accepts the - F option for compatibility with scripts written to call the old linker. - format input-format Synonym for - b input-format . - g Ignored. Provided for compatibility with other tools. - G value - G value Set the maximum size of objects to be optimized using the GP register to size under MIPS ECOFF. Ignored for other object file formats. - help Print a summary of the command-line options on the standard output and exit. - i Perform an incremental link (same as option - r ). - l ar Add archive file archive to the list of files to link. This option may be used any number of times. ld will search its path-list for occurrences of lib ar. a for every archive specified. - L searchdir - L searchdir 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. 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. - M Print (to the standard output) a link map--diagnostic information about where symbols are mapped by ld. and information on global common storage allocation. - Map mapfile Print to the file mapfile a link map--diagnostic information about where symbols are mapped by ld. and information on global common storage allocation. - m emulation - m emulation Emulate the emulation linker. You can list the available emulations with the --verbose or - V options. The default depends on how your ld was configured. - N Set the text and data sections to be readable and writable. Also, do not page-align the data segment. If the output format supports Unix style magic numbers, mark the output as OMAGIC. - n Set the text segment to be read only, and mark the output as NMAGIC if possible. - noinhibit-exec Retain the executable output file whenever it is still usable. Normally, the linker will not produce an output file if it encounters errors during the link process it exits without writing an output file when it issues any error whatsoever. - no-keep-memory ld normally optimizes for speed over memory usage by caching the symbol tables of input files in memory. This option tells ld to instead optimize for memory usage, by rereading the symbol tables as necessary. This may be required if ld runs out of memory space while linking a large executable. - o output 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. - oformat output-format ld may be configured to support more than one kind of object file. If your ld is configured this way, you can use the - oformat option to specify the binary format for the output object file. Even when ld is configured to support alternative object formats, you dont usually need to specify this, as ld should be configured to produce as a default output format the most usual format on each machine. output-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 .) The script command OUTPUTFORMAT can also specify the output format, but this option overrides it. See section BFD. - R filename 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. - relax An option with machine dependent effects. On some platforms, the - relax option performs global optimizations that become possible when the linker resolves addressing in the program, such as relaxing address modes and synthesizing new instructions in the output object file. - retain-symbols-file filename Retain only the symbols listed in the file filename. discarding all others. filename is simply a flat file, with one symbol name per line. This option is especially useful in environments where a large global symbol table is accumulated gradually, to conserve run-time memory. - retain-symbols-file does not discard undefined symbols, or symbols needed for relocations. You may only specify - retain-symbols-file once in the command line. It overrides - s and - S. - r 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. This option does the same thing as - i. - S Omit debugger symbol information (but not all symbols) from the output file. - s Omit all symbol information from the output file. - shared Create a shared library. This is currently only supported on ELF and SunOS platforms. On SunOS, the linker will automatically create a shared library if the - e option is not used and there are undefined symbols in the link. - sort-common Normally, when ld places the global common symbols in the appropriate output sections, it sorts them by size. First come all the one byte symbols, then all the two bytes, then all the four bytes, and then everything else. This is to prevent gaps between symbols due to alignment constraints. This option disables that sorting. - split-by-reloc count Trys to creates extra sections in the output file so that no single output section in the file contains more than count relocations. This is useful when generating huge relocatable for downloading into certain real time kernels with the COFF object file format since COFF cannot represent more than 65535 relocations in a single section. Note that this will fail to work with object file formats which do not support arbitrary sections. The linker will not split up individual input sections for redistribution, so if a single input section contains more than count relocations one output section will contain that many relocations. - split-by-file Similar to - split-by-reloc but creates a new output section for each input file. - stats Compute and display statistics about the operation of the linker, such as execution time and memory usage. - Tbss org - Tdata org - Ttext org Use org as the starting address for--respectively--the bss. data. or the text segment of the output file. org must be a single hexadecimal integer for compatibility with other linkers, you may omit the leading 0x usually associated with hexadecimal values. - T commandfile - T commandfile Read link commands from the file commandfile. These commands replace ld s default link script (rather than adding to it), so commandfile must specify everything necessary to describe the target format. See section Command Language. If commandfile does not exist, ld looks for it in the directories specified by any preceding - L options. Multiple - T options accumulate. - t Print the names of the input files as ld processes them. - traditional-format For some targets, the output of ld is different in some ways from the output of some existing linker. This switch requests ld to use the traditional format instead. For example, on SunOS, ld combines duplicate entries in the symbol string table. This can reduce the size of an output file with full debugging information by over 30 percent. Unfortunately, the SunOS dbx program can not read the resulting program ( gdb has no trouble). The - traditional-format switch tells ld to not combine duplicate entries. - u symbol 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. - Ur 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. --verbose Display the version number for ld and list the linker emulations supported. Display which input files can and cannot be opened. - v - V Display the version number for ld. The - V option also lists the supported emulations. - version Display the version number for ld and exit. - warn-common 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: int i 1 A definition, which goes in the initialized data section of the output file. extern int i An undefined reference, which does not allocate space. There must be either a definition or a common symbol for the variable somewhere. int i 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. Turning a common symbol into a reference, because there is already a definition for the symbol. 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. Merging a common symbol with a previous same-sized common symbol. Merging a common symbol with a previous larger common symbol. 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-constructors 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-once Only warn once for each undefined symbol, rather than once per module which refers to it. 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. next. last section, table of contents.

No comments:

Post a Comment