Options.html 155 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- This file documents the GNU linker LD
  4. (GNU Toolchain for the A-profile Architecture 10.2-2020.11 (arm-10.16))
  5. version 2.35.1.
  6. Copyright (C) 1991-2020 Free Software Foundation, Inc.
  7. Permission is granted to copy, distribute and/or modify this document
  8. under the terms of the GNU Free Documentation License, Version 1.3
  9. or any later version published by the Free Software Foundation;
  10. with no Invariant Sections, with no Front-Cover Texts, and with no
  11. Back-Cover Texts. A copy of the license is included in the
  12. section entitled "GNU Free Documentation License". -->
  13. <!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>LD: Options</title>
  16. <meta name="description" content="LD: Options">
  17. <meta name="keywords" content="LD: Options">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="LD-Index.html#LD-Index" rel="index" title="LD Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Invocation.html#Invocation" rel="up" title="Invocation">
  26. <link href="Environment.html#Environment" rel="next" title="Environment">
  27. <link href="Invocation.html#Invocation" rel="previous" title="Invocation">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style:oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Options"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Environment.html#Environment" accesskey="n" rel="next">Environment</a>, Up: <a href="Invocation.html#Invocation" accesskey="u" rel="up">Invocation</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
  62. </div>
  63. <hr>
  64. <a name="Command_002dline-Options"></a>
  65. <h3 class="section">2.1 Command-line Options</h3>
  66. <a name="index-command-line"></a>
  67. <a name="index-options"></a>
  68. <p>The linker supports a plethora of command-line options, but in actual
  69. practice few of them are used in any particular context.
  70. <a name="index-standard-Unix-system"></a>
  71. For instance, a frequent use of <code>ld</code> is to link standard Unix
  72. object files on a standard, supported Unix system. On such a system, to
  73. link a file <code>hello.o</code>:
  74. </p>
  75. <div class="smallexample">
  76. <pre class="smallexample">ld -o <var>output</var> /lib/crt0.o hello.o -lc
  77. </pre></div>
  78. <p>This tells <code>ld</code> to produce a file called <var>output</var> as the
  79. result of linking the file <code>/lib/crt0.o</code> with <code>hello.o</code> and
  80. the library <code>libc.a</code>, which will come from the standard search
  81. directories. (See the discussion of the &lsquo;<samp>-l</samp>&rsquo; option below.)
  82. </p>
  83. <p>Some of the command-line options to <code>ld</code> may be specified at any
  84. point in the command line. However, options which refer to files, such
  85. as &lsquo;<samp>-l</samp>&rsquo; or &lsquo;<samp>-T</samp>&rsquo;, cause the file to be read at the point at
  86. which the option appears in the command line, relative to the object
  87. files and other file options. Repeating non-file options with a
  88. different argument will either have no further effect, or override prior
  89. occurrences (those further to the left on the command line) of that
  90. option. Options which may be meaningfully specified more than once are
  91. noted in the descriptions below.
  92. </p>
  93. <a name="index-object-files"></a>
  94. <p>Non-option arguments are object files or archives which are to be linked
  95. together. They may follow, precede, or be mixed in with command-line
  96. options, except that an object file argument may not be placed between
  97. an option and its argument.
  98. </p>
  99. <p>Usually the linker is invoked with at least one object file, but you can
  100. specify other forms of binary input files using &lsquo;<samp>-l</samp>&rsquo;, &lsquo;<samp>-R</samp>&rsquo;,
  101. and the script command language. If <em>no</em> binary input files at all
  102. are specified, the linker does not produce any output, and issues the
  103. message &lsquo;<samp>No input files</samp>&rsquo;.
  104. </p>
  105. <p>If the linker cannot recognize the format of an object file, it will
  106. assume that it is a linker script. A script specified in this way
  107. augments the main linker script used for the link (either the default
  108. linker script or the one specified by using &lsquo;<samp>-T</samp>&rsquo;). This feature
  109. permits the linker to link against a file which appears to be an object
  110. or an archive, but actually merely defines some symbol values, or uses
  111. <code>INPUT</code> or <code>GROUP</code> to load other objects. Specifying a
  112. script in this way merely augments the main linker script, with the
  113. extra commands placed after the main script; use the &lsquo;<samp>-T</samp>&rsquo; option
  114. to replace the default linker script entirely, but note the effect of
  115. the <code>INSERT</code> command. See <a href="Scripts.html#Scripts">Scripts</a>.
  116. </p>
  117. <p>For options whose names are a single letter,
  118. option arguments must either follow the option letter without intervening
  119. whitespace, or be given as separate arguments immediately following the
  120. option that requires them.
  121. </p>
  122. <p>For options whose names are multiple letters, either one dash or two can
  123. precede the option name; for example, &lsquo;<samp>-trace-symbol</samp>&rsquo; and
  124. &lsquo;<samp>--trace-symbol</samp>&rsquo; are equivalent. Note&mdash;there is one exception to
  125. this rule. Multiple letter options that start with a lower case &rsquo;o&rsquo; can
  126. only be preceded by two dashes. This is to reduce confusion with the
  127. &lsquo;<samp>-o</samp>&rsquo; option. So for example &lsquo;<samp>-omagic</samp>&rsquo; sets the output file
  128. name to &lsquo;<samp>magic</samp>&rsquo; whereas &lsquo;<samp>--omagic</samp>&rsquo; sets the NMAGIC flag on the
  129. output.
  130. </p>
  131. <p>Arguments to multiple-letter options must either be separated from the
  132. option name by an equals sign, or be given as separate arguments
  133. immediately following the option that requires them. For example,
  134. &lsquo;<samp>--trace-symbol foo</samp>&rsquo; and &lsquo;<samp>--trace-symbol=foo</samp>&rsquo; are equivalent.
  135. Unique abbreviations of the names of multiple-letter options are
  136. accepted.
  137. </p>
  138. <p>Note&mdash;if the linker is being invoked indirectly, via a compiler driver
  139. (e.g. &lsquo;<samp>gcc</samp>&rsquo;) then all the linker command-line options should be
  140. prefixed by &lsquo;<samp>-Wl,</samp>&rsquo; (or whatever is appropriate for the particular
  141. compiler driver) like this:
  142. </p>
  143. <div class="smallexample">
  144. <pre class="smallexample"> gcc -Wl,--start-group foo.o bar.o -Wl,--end-group
  145. </pre></div>
  146. <p>This is important, because otherwise the compiler driver program may
  147. silently drop the linker options, resulting in a bad link. Confusion
  148. may also arise when passing options that require values through a
  149. driver, as the use of a space between option and argument acts as
  150. a separator, and causes the driver to pass only the option to the linker
  151. and the argument to the compiler. In this case, it is simplest to use
  152. the joined forms of both single- and multiple-letter options, such as:
  153. </p>
  154. <div class="smallexample">
  155. <pre class="smallexample"> gcc foo.o bar.o -Wl,-eENTRY -Wl,-Map=a.map
  156. </pre></div>
  157. <p>Here is a table of the generic command-line switches accepted by the GNU
  158. linker:
  159. </p>
  160. <dl compact="compact">
  161. <dt><code>@<var>file</var></code></dt>
  162. <dd><p>Read command-line options from <var>file</var>. The options read are
  163. inserted in place of the original @<var>file</var> option. If <var>file</var>
  164. does not exist, or cannot be read, then the option will be treated
  165. literally, and not removed.
  166. </p>
  167. <p>Options in <var>file</var> are separated by whitespace. A whitespace
  168. character may be included in an option by surrounding the entire
  169. option in either single or double quotes. Any character (including a
  170. backslash) may be included by prefixing the character to be included
  171. with a backslash. The <var>file</var> may itself contain additional
  172. @<var>file</var> options; any such options will be processed recursively.
  173. </p>
  174. <a name="index-_002da-keyword"></a>
  175. </dd>
  176. <dt><code>-a <var>keyword</var></code></dt>
  177. <dd><p>This option is supported for HP/UX compatibility. The <var>keyword</var>
  178. argument must be one of the strings &lsquo;<samp>archive</samp>&rsquo;, &lsquo;<samp>shared</samp>&rsquo;, or
  179. &lsquo;<samp>default</samp>&rsquo;. &lsquo;<samp>-aarchive</samp>&rsquo; is functionally equivalent to
  180. &lsquo;<samp>-Bstatic</samp>&rsquo;, and the other two keywords are functionally equivalent
  181. to &lsquo;<samp>-Bdynamic</samp>&rsquo;. This option may be used any number of times.
  182. </p>
  183. <a name="index-_002d_002daudit-AUDITLIB"></a>
  184. </dd>
  185. <dt><code>--audit <var>AUDITLIB</var></code></dt>
  186. <dd><p>Adds <var>AUDITLIB</var> to the <code>DT_AUDIT</code> entry of the dynamic section.
  187. <var>AUDITLIB</var> is not checked for existence, nor will it use the DT_SONAME
  188. specified in the library. If specified multiple times <code>DT_AUDIT</code>
  189. will contain a colon separated list of audit interfaces to use. If the linker
  190. finds an object with an audit entry while searching for shared libraries,
  191. it will add a corresponding <code>DT_DEPAUDIT</code> entry in the output file.
  192. This option is only meaningful on ELF platforms supporting the rtld-audit
  193. interface.
  194. </p>
  195. <a name="index-binary-input-format"></a>
  196. <a name="index-_002db-format"></a>
  197. <a name="index-_002d_002dformat_003dformat"></a>
  198. <a name="index-input-format"></a>
  199. <a name="index-input-format-1"></a>
  200. </dd>
  201. <dt><code>-b <var>input-format</var></code></dt>
  202. <dt><code>--format=<var>input-format</var></code></dt>
  203. <dd><p><code>ld</code> may be configured to support more than one kind of object
  204. file. If your <code>ld</code> is configured this way, you can use the
  205. &lsquo;<samp>-b</samp>&rsquo; option to specify the binary format for input object files
  206. that follow this option on the command line. Even when <code>ld</code> is
  207. configured to support alternative object formats, you don&rsquo;t usually need
  208. to specify this, as <code>ld</code> should be configured to expect as a
  209. default input format the most usual format on each machine.
  210. <var>input-format</var> is a text string, the name of a particular format
  211. supported by the BFD libraries. (You can list the available binary
  212. formats with &lsquo;<samp>objdump -i</samp>&rsquo;.)
  213. See <a href="BFD.html#BFD">BFD</a>.
  214. </p>
  215. <p>You may want to use this option if you are linking files with an unusual
  216. binary format. You can also use &lsquo;<samp>-b</samp>&rsquo; to switch formats explicitly (when
  217. linking object files of different formats), by including
  218. &lsquo;<samp>-b <var>input-format</var></samp>&rsquo; before each group of object files in a
  219. particular format.
  220. </p>
  221. <p>The default format is taken from the environment variable
  222. <code>GNUTARGET</code>.
  223. See <a href="Environment.html#Environment">Environment</a>.
  224. You can also define the input format from a script, using the command
  225. <code>TARGET</code>;
  226. see <a href="Format-Commands.html#Format-Commands">Format Commands</a>.
  227. </p>
  228. <a name="index-_002dc-MRI_002dcmdfile"></a>
  229. <a name="index-_002d_002dmri_002dscript_003dMRI_002dcmdfile"></a>
  230. <a name="index-compatibility_002c-MRI"></a>
  231. </dd>
  232. <dt><code>-c <var>MRI-commandfile</var></code></dt>
  233. <dt><code>--mri-script=<var>MRI-commandfile</var></code></dt>
  234. <dd><p>For compatibility with linkers produced by MRI, <code>ld</code> accepts script
  235. files written in an alternate, restricted command language, described in
  236. <a href="MRI.html#MRI">MRI Compatible Script Files</a>.
  237. Introduce MRI script files with
  238. the option &lsquo;<samp>-c</samp>&rsquo;; use the &lsquo;<samp>-T</samp>&rsquo; option to run linker
  239. scripts written in the general-purpose <code>ld</code> scripting language.
  240. If <var>MRI-cmdfile</var> does not exist, <code>ld</code> looks for it in the directories
  241. specified by any &lsquo;<samp>-L</samp>&rsquo; options.
  242. </p>
  243. <a name="index-common-allocation"></a>
  244. <a name="index-_002dd"></a>
  245. <a name="index-_002ddc"></a>
  246. <a name="index-_002ddp"></a>
  247. </dd>
  248. <dt><code>-d</code></dt>
  249. <dt><code>-dc</code></dt>
  250. <dt><code>-dp</code></dt>
  251. <dd><p>These three options are equivalent; multiple forms are supported for
  252. compatibility with other linkers. They assign space to common symbols
  253. even if a relocatable output file is specified (with &lsquo;<samp>-r</samp>&rsquo;). The
  254. script command <code>FORCE_COMMON_ALLOCATION</code> has the same effect.
  255. See <a href="Miscellaneous-Commands.html#Miscellaneous-Commands">Miscellaneous Commands</a>.
  256. </p>
  257. <a name="index-_002d_002ddepaudit-AUDITLIB"></a>
  258. <a name="index-_002dP-AUDITLIB"></a>
  259. </dd>
  260. <dt><code>--depaudit <var>AUDITLIB</var></code></dt>
  261. <dt><code>-P <var>AUDITLIB</var></code></dt>
  262. <dd><p>Adds <var>AUDITLIB</var> to the <code>DT_DEPAUDIT</code> entry of the dynamic section.
  263. <var>AUDITLIB</var> is not checked for existence, nor will it use the DT_SONAME
  264. specified in the library. If specified multiple times <code>DT_DEPAUDIT</code>
  265. will contain a colon separated list of audit interfaces to use. This
  266. option is only meaningful on ELF platforms supporting the rtld-audit interface.
  267. The -P option is provided for Solaris compatibility.
  268. </p>
  269. <a name="index-_002d_002denable_002dnon_002dcontiguous_002dregions"></a>
  270. </dd>
  271. <dt><code>--enable-non-contiguous-regions</code></dt>
  272. <dd><p>This option avoids generating an error if an input section does not
  273. fit a matching output section. The linker tries to allocate the input
  274. section to subseque nt matching output sections, and generates an
  275. error only if no output section is large enough. This is useful when
  276. several non-contiguous memory regions are available and the input
  277. section does not require a particular one. The order in which input
  278. sections are evaluated does not change, for instance:
  279. </p>
  280. <div class="smallexample">
  281. <pre class="smallexample"> MEMORY {
  282. MEM1 (rwx) : ORIGIN : 0x1000, LENGTH = 0x14
  283. MEM2 (rwx) : ORIGIN : 0x1000, LENGTH = 0x40
  284. MEM3 (rwx) : ORIGIN : 0x2000, LENGTH = 0x40
  285. }
  286. SECTIONS {
  287. mem1 : { *(.data.*); } &gt; MEM1
  288. mem2 : { *(.data.*); } &gt; MEM2
  289. mem3 : { *(.data.*); } &gt; MEM2
  290. }
  291. with input sections:
  292. .data.1: size 8
  293. .data.2: size 0x10
  294. .data.3: size 4
  295. results in .data.1 affected to mem1, and .data.2 and .data.3
  296. affected to mem2, even though .data.3 would fit in mem3.
  297. </pre></div>
  298. <p>This option is incompatible with INSERT statements because it changes
  299. the way input sections are mapped to output sections.
  300. </p>
  301. <a name="index-_002d_002denable_002dnon_002dcontiguous_002dregions_002dwarnings"></a>
  302. </dd>
  303. <dt><code>--enable-non-contiguous-regions-warnings</code></dt>
  304. <dd><p>This option enables warnings when
  305. <code>--enable-non-contiguous-regions</code> allows possibly unexpected
  306. matches in sections mapping, potentially leading to silently
  307. discarding a section instead of failing because it does not fit any
  308. output region.
  309. </p>
  310. <a name="index-entry-point_002c-from-command-line"></a>
  311. <a name="index-_002de-entry"></a>
  312. <a name="index-_002d_002dentry_003dentry"></a>
  313. </dd>
  314. <dt><code>-e <var>entry</var></code></dt>
  315. <dt><code>--entry=<var>entry</var></code></dt>
  316. <dd><p>Use <var>entry</var> as the explicit symbol for beginning execution of your
  317. program, rather than the default entry point. If there is no symbol
  318. named <var>entry</var>, the linker will try to parse <var>entry</var> as a number,
  319. and use that as the entry address (the number will be interpreted in
  320. base 10; you may use a leading &lsquo;<samp>0x</samp>&rsquo; for base 16, or a leading
  321. &lsquo;<samp>0</samp>&rsquo; for base 8). See <a href="Entry-Point.html#Entry-Point">Entry Point</a>, for a discussion of defaults
  322. and other ways of specifying the entry point.
  323. </p>
  324. <a name="index-_002d_002dexclude_002dlibs"></a>
  325. </dd>
  326. <dt><code>--exclude-libs <var>lib</var>,<var>lib</var>,...</code></dt>
  327. <dd><p>Specifies a list of archive libraries from which symbols should not be automatically
  328. exported. The library names may be delimited by commas or colons. Specifying
  329. <code>--exclude-libs ALL</code> excludes symbols in all archive libraries from
  330. automatic export. This option is available only for the i386 PE targeted
  331. port of the linker and for ELF targeted ports. For i386 PE, symbols
  332. explicitly listed in a .def file are still exported, regardless of this
  333. option. For ELF targeted ports, symbols affected by this option will
  334. be treated as hidden.
  335. </p>
  336. <a name="index-_002d_002dexclude_002dmodules_002dfor_002dimplib"></a>
  337. </dd>
  338. <dt><code>--exclude-modules-for-implib <var>module</var>,<var>module</var>,...</code></dt>
  339. <dd><p>Specifies a list of object files or archive members, from which symbols
  340. should not be automatically exported, but which should be copied wholesale
  341. into the import library being generated during the link. The module names
  342. may be delimited by commas or colons, and must match exactly the filenames
  343. used by <code>ld</code> to open the files; for archive members, this is simply
  344. the member name, but for object files the name listed must include and
  345. match precisely any path used to specify the input file on the linker&rsquo;s
  346. command-line. This option is available only for the i386 PE targeted port
  347. of the linker. Symbols explicitly listed in a .def file are still exported,
  348. regardless of this option.
  349. </p>
  350. <a name="index-dynamic-symbol-table"></a>
  351. <a name="index-_002dE"></a>
  352. <a name="index-_002d_002dexport_002ddynamic"></a>
  353. <a name="index-_002d_002dno_002dexport_002ddynamic"></a>
  354. </dd>
  355. <dt><code>-E</code></dt>
  356. <dt><code>--export-dynamic</code></dt>
  357. <dt><code>--no-export-dynamic</code></dt>
  358. <dd><p>When creating a dynamically linked executable, using the <samp>-E</samp>
  359. option or the <samp>--export-dynamic</samp> option causes the linker to add
  360. all symbols to the dynamic symbol table. The dynamic symbol table is the
  361. set of symbols which are visible from dynamic objects at run time.
  362. </p>
  363. <p>If you do not use either of these options (or use the
  364. <samp>--no-export-dynamic</samp> option to restore the default behavior), the
  365. dynamic symbol table will normally contain only those symbols which are
  366. referenced by some dynamic object mentioned in the link.
  367. </p>
  368. <p>If you use <code>dlopen</code> to load a dynamic object which needs to refer
  369. back to the symbols defined by the program, rather than some other
  370. dynamic object, then you will probably need to use this option when
  371. linking the program itself.
  372. </p>
  373. <p>You can also use the dynamic list to control what symbols should
  374. be added to the dynamic symbol table if the output format supports it.
  375. See the description of &lsquo;<samp>--dynamic-list</samp>&rsquo;.
  376. </p>
  377. <p>Note that this option is specific to ELF targeted ports. PE targets
  378. support a similar function to export all symbols from a DLL or EXE; see
  379. the description of &lsquo;<samp>--export-all-symbols</samp>&rsquo; below.
  380. </p>
  381. <a name="index-_002d_002dexport_002ddynamic_002dsymbol_003dglob"></a>
  382. <a name="index-export-dynamic-symbol"></a>
  383. </dd>
  384. <dt><code>--export-dynamic-symbol=<var>glob</var></code></dt>
  385. <dd><p>When creating a dynamically linked executable, symbols matching
  386. <var>glob</var> will be added to the dynamic symbol table. When creating a
  387. shared library, references to symbols matching <var>glob</var> will not be
  388. bound to the definitions within the shared library. This option is a
  389. no-op when creating a shared library and &lsquo;<samp>-Bsymbolic</samp>&rsquo; or
  390. &lsquo;<samp>--dynamic-list</samp>&rsquo; are not specified. This option is only meaningful
  391. on ELF platforms which support shared libraries.
  392. </p>
  393. <a name="index-_002d_002dexport_002ddynamic_002dsymbol_002dlist_003dfile"></a>
  394. <a name="index-export-dynamic-symbol-list"></a>
  395. </dd>
  396. <dt><code>--export-dynamic-symbol-list=<var>file</var></code></dt>
  397. <dd><p>Specify a &lsquo;<samp>--export-dynamic-symbol</samp>&rsquo; for each pattern in the file.
  398. The format of the file is the same as the version node without
  399. scope and node name. See <a href="VERSION.html#VERSION">VERSION</a> for more information.
  400. </p>
  401. <a name="index-big_002dendian-objects"></a>
  402. <a name="index-endianness"></a>
  403. <a name="index-_002dEB"></a>
  404. </dd>
  405. <dt><code>-EB</code></dt>
  406. <dd><p>Link big-endian objects. This affects the default output format.
  407. </p>
  408. <a name="index-little_002dendian-objects"></a>
  409. <a name="index-_002dEL"></a>
  410. </dd>
  411. <dt><code>-EL</code></dt>
  412. <dd><p>Link little-endian objects. This affects the default output format.
  413. </p>
  414. <a name="index-_002df-name"></a>
  415. <a name="index-_002d_002dauxiliary_003dname"></a>
  416. </dd>
  417. <dt><code>-f <var>name</var></code></dt>
  418. <dt><code>--auxiliary=<var>name</var></code></dt>
  419. <dd><p>When creating an ELF shared object, set the internal DT_AUXILIARY field
  420. to the specified name. This tells the dynamic linker that the symbol
  421. table of the shared object should be used as an auxiliary filter on the
  422. symbol table of the shared object <var>name</var>.
  423. </p>
  424. <p>If you later link a program against this filter object, then, when you
  425. run the program, the dynamic linker will see the DT_AUXILIARY field. If
  426. the dynamic linker resolves any symbols from the filter object, it will
  427. first check whether there is a definition in the shared object
  428. <var>name</var>. If there is one, it will be used instead of the definition
  429. in the filter object. The shared object <var>name</var> need not exist.
  430. Thus the shared object <var>name</var> may be used to provide an alternative
  431. implementation of certain functions, perhaps for debugging or for
  432. machine-specific performance.
  433. </p>
  434. <p>This option may be specified more than once. The DT_AUXILIARY entries
  435. will be created in the order in which they appear on the command line.
  436. </p>
  437. <a name="index-_002dF-name"></a>
  438. <a name="index-_002d_002dfilter_003dname"></a>
  439. </dd>
  440. <dt><code>-F <var>name</var></code></dt>
  441. <dt><code>--filter=<var>name</var></code></dt>
  442. <dd><p>When creating an ELF shared object, set the internal DT_FILTER field to
  443. the specified name. This tells the dynamic linker that the symbol table
  444. of the shared object which is being created should be used as a filter
  445. on the symbol table of the shared object <var>name</var>.
  446. </p>
  447. <p>If you later link a program against this filter object, then, when you
  448. run the program, the dynamic linker will see the DT_FILTER field. The
  449. dynamic linker will resolve symbols according to the symbol table of the
  450. filter object as usual, but it will actually link to the definitions
  451. found in the shared object <var>name</var>. Thus the filter object can be
  452. used to select a subset of the symbols provided by the object
  453. <var>name</var>.
  454. </p>
  455. <p>Some older linkers used the <samp>-F</samp> option throughout a compilation
  456. toolchain for specifying object-file format for both input and output
  457. object files.
  458. The <small>GNU</small> linker uses other mechanisms for this purpose: the
  459. <samp>-b</samp>, <samp>--format</samp>, <samp>--oformat</samp> options, the
  460. <code>TARGET</code> command in linker scripts, and the <code>GNUTARGET</code>
  461. environment variable.
  462. The <small>GNU</small> linker will ignore the <samp>-F</samp> option when not
  463. creating an ELF shared object.
  464. </p>
  465. <a name="index-finalization-function"></a>
  466. <a name="index-_002dfini_003dname"></a>
  467. </dd>
  468. <dt><code>-fini=<var>name</var></code></dt>
  469. <dd><p>When creating an ELF executable or shared object, call NAME when the
  470. executable or shared object is unloaded, by setting DT_FINI to the
  471. address of the function. By default, the linker uses <code>_fini</code> as
  472. the function to call.
  473. </p>
  474. <a name="index-_002dg"></a>
  475. </dd>
  476. <dt><code>-g</code></dt>
  477. <dd><p>Ignored. Provided for compatibility with other tools.
  478. </p>
  479. <a name="index-_002dG-value"></a>
  480. <a name="index-_002d_002dgpsize_003dvalue"></a>
  481. <a name="index-object-size"></a>
  482. </dd>
  483. <dt><code>-G <var>value</var></code></dt>
  484. <dt><code>--gpsize=<var>value</var></code></dt>
  485. <dd><p>Set the maximum size of objects to be optimized using the GP register to
  486. <var>size</var>. This is only meaningful for object file formats such as
  487. MIPS ELF that support putting large and small objects into different
  488. sections. This is ignored for other object file formats.
  489. </p>
  490. <a name="index-runtime-library-name"></a>
  491. <a name="index-_002dh-name"></a>
  492. <a name="index-_002dsoname_003dname"></a>
  493. </dd>
  494. <dt><code>-h <var>name</var></code></dt>
  495. <dt><code>-soname=<var>name</var></code></dt>
  496. <dd><p>When creating an ELF shared object, set the internal DT_SONAME field to
  497. the specified name. When an executable is linked with a shared object
  498. which has a DT_SONAME field, then when the executable is run the dynamic
  499. linker will attempt to load the shared object specified by the DT_SONAME
  500. field rather than the using the file name given to the linker.
  501. </p>
  502. <a name="index-_002di"></a>
  503. <a name="index-incremental-link"></a>
  504. </dd>
  505. <dt><code>-i</code></dt>
  506. <dd><p>Perform an incremental link (same as option &lsquo;<samp>-r</samp>&rsquo;).
  507. </p>
  508. <a name="index-initialization-function"></a>
  509. <a name="index-_002dinit_003dname"></a>
  510. </dd>
  511. <dt><code>-init=<var>name</var></code></dt>
  512. <dd><p>When creating an ELF executable or shared object, call NAME when the
  513. executable or shared object is loaded, by setting DT_INIT to the address
  514. of the function. By default, the linker uses <code>_init</code> as the
  515. function to call.
  516. </p>
  517. <a name="index-archive-files_002c-from-cmd-line"></a>
  518. <a name="index-_002dl-namespec"></a>
  519. <a name="index-_002d_002dlibrary_003dnamespec"></a>
  520. </dd>
  521. <dt><code>-l <var>namespec</var></code></dt>
  522. <dt><code>--library=<var>namespec</var></code></dt>
  523. <dd><p>Add the archive or object file specified by <var>namespec</var> to the
  524. list of files to link. This option may be used any number of times.
  525. If <var>namespec</var> is of the form <samp>:<var>filename</var></samp>, <code>ld</code>
  526. will search the library path for a file called <var>filename</var>, otherwise it
  527. will search the library path for a file called <samp>lib<var>namespec</var>.a</samp>.
  528. </p>
  529. <p>On systems which support shared libraries, <code>ld</code> may also search for
  530. files other than <samp>lib<var>namespec</var>.a</samp>. Specifically, on ELF
  531. and SunOS systems, <code>ld</code> will search a directory for a library
  532. called <samp>lib<var>namespec</var>.so</samp> before searching for one called
  533. <samp>lib<var>namespec</var>.a</samp>. (By convention, a <code>.so</code> extension
  534. indicates a shared library.) Note that this behavior does not apply
  535. to <samp>:<var>filename</var></samp>, which always specifies a file called
  536. <var>filename</var>.
  537. </p>
  538. <p>The linker will search an archive only once, at the location where it is
  539. specified on the command line. If the archive defines a symbol which
  540. was undefined in some object which appeared before the archive on the
  541. command line, the linker will include the appropriate file(s) from the
  542. archive. However, an undefined symbol in an object appearing later on
  543. the command line will not cause the linker to search the archive again.
  544. </p>
  545. <p>See the <samp>-(</samp> option for a way to force the linker to search
  546. archives multiple times.
  547. </p>
  548. <p>You may list the same archive multiple times on the command line.
  549. </p>
  550. <p>This type of archive searching is standard for Unix linkers. However,
  551. if you are using <code>ld</code> on AIX, note that it is different from the
  552. behaviour of the AIX linker.
  553. </p>
  554. <a name="index-search-directory_002c-from-cmd-line"></a>
  555. <a name="index-_002dL-dir"></a>
  556. <a name="index-_002d_002dlibrary_002dpath_003ddir"></a>
  557. </dd>
  558. <dt><code>-L <var>searchdir</var></code></dt>
  559. <dt><code>--library-path=<var>searchdir</var></code></dt>
  560. <dd><p>Add path <var>searchdir</var> to the list of paths that <code>ld</code> will search
  561. for archive libraries and <code>ld</code> control scripts. You may use this
  562. option any number of times. The directories are searched in the order
  563. in which they are specified on the command line. Directories specified
  564. on the command line are searched before the default directories. All
  565. <samp>-L</samp> options apply to all <samp>-l</samp> options, regardless of the
  566. order in which the options appear. <samp>-L</samp> options do not affect
  567. how <code>ld</code> searches for a linker script unless <samp>-T</samp>
  568. option is specified.
  569. </p>
  570. <p>If <var>searchdir</var> begins with <code>=</code> or <code>$SYSROOT</code>, then this
  571. prefix will be replaced by the <em>sysroot prefix</em>, controlled by the
  572. &lsquo;<samp>--sysroot</samp>&rsquo; option, or specified when the linker is configured.
  573. </p>
  574. <p>The default set of paths searched (without being specified with
  575. &lsquo;<samp>-L</samp>&rsquo;) depends on which emulation mode <code>ld</code> is using, and in
  576. some cases also on how it was configured. See <a href="Environment.html#Environment">Environment</a>.
  577. </p>
  578. <p>The paths can also be specified in a link script with the
  579. <code>SEARCH_DIR</code> command. Directories specified this way are searched
  580. at the point in which the linker script appears in the command line.
  581. </p>
  582. <a name="index-emulation"></a>
  583. <a name="index-_002dm-emulation"></a>
  584. </dd>
  585. <dt><code>-m <var>emulation</var></code></dt>
  586. <dd><p>Emulate the <var>emulation</var> linker. You can list the available
  587. emulations with the &lsquo;<samp>--verbose</samp>&rsquo; or &lsquo;<samp>-V</samp>&rsquo; options.
  588. </p>
  589. <p>If the &lsquo;<samp>-m</samp>&rsquo; option is not used, the emulation is taken from the
  590. <code>LDEMULATION</code> environment variable, if that is defined.
  591. </p>
  592. <p>Otherwise, the default emulation depends upon how the linker was
  593. configured.
  594. </p>
  595. <a name="index-link-map"></a>
  596. <a name="index-_002dM"></a>
  597. <a name="index-_002d_002dprint_002dmap"></a>
  598. </dd>
  599. <dt><code>-M</code></dt>
  600. <dt><code>--print-map</code></dt>
  601. <dd><p>Print a link map to the standard output. A link map provides
  602. information about the link, including the following:
  603. </p>
  604. <ul>
  605. <li> Where object files are mapped into memory.
  606. </li><li> How common symbols are allocated.
  607. </li><li> All archive members included in the link, with a mention of the symbol
  608. which caused the archive member to be brought in.
  609. </li><li> The values assigned to symbols.
  610. <p>Note - symbols whose values are computed by an expression which
  611. involves a reference to a previous value of the same symbol may not
  612. have correct result displayed in the link map. This is because the
  613. linker discards intermediate results and only retains the final value
  614. of an expression. Under such circumstances the linker will display
  615. the final value enclosed by square brackets. Thus for example a
  616. linker script containing:
  617. </p>
  618. <div class="smallexample">
  619. <pre class="smallexample"> foo = 1
  620. foo = foo * 4
  621. foo = foo + 8
  622. </pre></div>
  623. <p>will produce the following output in the link map if the <samp>-M</samp>
  624. option is used:
  625. </p>
  626. <div class="smallexample">
  627. <pre class="smallexample"> 0x00000001 foo = 0x1
  628. [0x0000000c] foo = (foo * 0x4)
  629. [0x0000000c] foo = (foo + 0x8)
  630. </pre></div>
  631. <p>See <a href="Expressions.html#Expressions">Expressions</a> for more information about expressions in linker
  632. scripts.
  633. </p>
  634. </li><li> How GNU properties are merged.
  635. <p>When the linker merges input .note.gnu.property sections into one output
  636. .note.gnu.property section, some properties are removed or updated.
  637. These actions are reported in the link map. For example:
  638. </p>
  639. <div class="smallexample">
  640. <pre class="smallexample">Removed property 0xc0000002 to merge foo.o (0x1) and bar.o (not found)
  641. </pre></div>
  642. <p>This indicates that property 0xc0000002 is removed from output when
  643. merging properties in <samp>foo.o</samp>, whose property 0xc0000002 value
  644. is 0x1, and <samp>bar.o</samp>, which doesn&rsquo;t have property 0xc0000002.
  645. </p>
  646. <div class="smallexample">
  647. <pre class="smallexample">Updated property 0xc0010001 (0x1) to merge foo.o (0x1) and bar.o (0x1)
  648. </pre></div>
  649. <p>This indicates that property 0xc0010001 value is updated to 0x1 in output
  650. when merging properties in <samp>foo.o</samp>, whose 0xc0010001 property value
  651. is 0x1, and <samp>bar.o</samp>, whose 0xc0010001 property value is 0x1.
  652. </p></li></ul>
  653. <a name="index-link-map-discarded"></a>
  654. <a name="index-_002d_002dprint_002dmap_002ddiscarded"></a>
  655. <a name="index-_002d_002dno_002dprint_002dmap_002ddiscarded"></a>
  656. </dd>
  657. <dt><code>--print-map-discarded</code></dt>
  658. <dt><code>--no-print-map-discarded</code></dt>
  659. <dd><p>Print (or do not print) the list of discarded and garbage collected sections
  660. in the link map. Enabled by default.
  661. </p>
  662. <a name="index-_002dn"></a>
  663. <a name="index-read_002donly-text"></a>
  664. <a name="index-NMAGIC"></a>
  665. <a name="index-_002d_002dnmagic"></a>
  666. </dd>
  667. <dt><code>-n</code></dt>
  668. <dt><code>--nmagic</code></dt>
  669. <dd><p>Turn off page alignment of sections, and disable linking against shared
  670. libraries. If the output format supports Unix style magic numbers,
  671. mark the output as <code>NMAGIC</code>.
  672. </p>
  673. <a name="index-_002dN"></a>
  674. <a name="index-_002d_002domagic"></a>
  675. <a name="index-read_002fwrite-from-cmd-line"></a>
  676. <a name="index-OMAGIC"></a>
  677. </dd>
  678. <dt><code>-N</code></dt>
  679. <dt><code>--omagic</code></dt>
  680. <dd><p>Set the text and data sections to be readable and writable. Also, do
  681. not page-align the data segment, and disable linking against shared
  682. libraries. If the output format supports Unix style magic numbers,
  683. mark the output as <code>OMAGIC</code>. Note: Although a writable text section
  684. is allowed for PE-COFF targets, it does not conform to the format
  685. specification published by Microsoft.
  686. </p>
  687. <a name="index-_002d_002dno_002domagic"></a>
  688. <a name="index-OMAGIC-1"></a>
  689. </dd>
  690. <dt><code>--no-omagic</code></dt>
  691. <dd><p>This option negates most of the effects of the <samp>-N</samp> option. It
  692. sets the text section to be read-only, and forces the data segment to
  693. be page-aligned. Note - this option does not enable linking against
  694. shared libraries. Use <samp>-Bdynamic</samp> for this.
  695. </p>
  696. <a name="index-_002do-output"></a>
  697. <a name="index-_002d_002doutput_003doutput"></a>
  698. <a name="index-naming-the-output-file"></a>
  699. </dd>
  700. <dt><code>-o <var>output</var></code></dt>
  701. <dt><code>--output=<var>output</var></code></dt>
  702. <dd><p>Use <var>output</var> as the name for the program produced by <code>ld</code>; if this
  703. option is not specified, the name <samp>a.out</samp> is used by default. The
  704. script command <code>OUTPUT</code> can also specify the output file name.
  705. </p>
  706. <a name="index-_002d_002ddependency_002dfile_003ddepfile"></a>
  707. <a name="index-dependency-file"></a>
  708. </dd>
  709. <dt><code>--dependency-file=<var>depfile</var></code></dt>
  710. <dd><p>Write a <em>dependency file</em> to <var>depfile</var>. This file contains a rule
  711. suitable for <code>make</code> describing the output file and all the input files
  712. that were read to produce it. The output is similar to the compiler&rsquo;s
  713. output with &lsquo;<samp>-M -MP</samp>&rsquo; (see <a href="http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html#Preprocessor-Options">Options
  714. Controlling the Preprocessor</a> in <cite>Using the GNU Compiler
  715. Collection</cite>). Note that there is no option like the compiler&rsquo;s &lsquo;<samp>-MM</samp>&rsquo;,
  716. to exclude &ldquo;system files&rdquo; (which is not a well-specified concept in the
  717. linker, unlike &ldquo;system headers&rdquo; in the compiler). So the output from
  718. &lsquo;<samp>--dependency-file</samp>&rsquo; is always specific to the exact state of the
  719. installation where it was produced, and should not be copied into
  720. distributed makefiles without careful editing.
  721. </p>
  722. <a name="index-_002dO-level"></a>
  723. <a name="index-generating-optimized-output"></a>
  724. </dd>
  725. <dt><code>-O <var>level</var></code></dt>
  726. <dd><p>If <var>level</var> is a numeric values greater than zero <code>ld</code> optimizes
  727. the output. This might take significantly longer and therefore probably
  728. should only be enabled for the final binary. At the moment this
  729. option only affects ELF shared library generation. Future releases of
  730. the linker may make more use of this option. Also currently there is
  731. no difference in the linker&rsquo;s behaviour for different non-zero values
  732. of this option. Again this may change with future releases.
  733. </p>
  734. <a name="index-_002dplugin-name"></a>
  735. </dd>
  736. <dt><code>-plugin <var>name</var></code></dt>
  737. <dd><p>Involve a plugin in the linking process. The <var>name</var> parameter is
  738. the absolute filename of the plugin. Usually this parameter is
  739. automatically added by the complier, when using link time
  740. optimization, but users can also add their own plugins if they so
  741. wish.
  742. </p>
  743. <p>Note that the location of the compiler originated plugins is different
  744. from the place where the <code>ar</code>, <code>nm</code> and
  745. <code>ranlib</code> programs search for their plugins. In order for
  746. those commands to make use of a compiler based plugin it must first be
  747. copied into the <samp>${libdir}/bfd-plugins</samp> directory. All gcc
  748. based linker plugins are backward compatible, so it is sufficient to
  749. just copy in the newest one.
  750. </p>
  751. <a name="index-_002d_002dpush_002dstate"></a>
  752. <a name="index-push-state-governing-input-file-handling"></a>
  753. </dd>
  754. <dt><code>--push-state</code></dt>
  755. <dd><p>The <samp>--push-state</samp> allows to preserve the current state of the
  756. flags which govern the input file handling so that they can all be
  757. restored with one corresponding <samp>--pop-state</samp> option.
  758. </p>
  759. <p>The option which are covered are: <samp>-Bdynamic</samp>, <samp>-Bstatic</samp>,
  760. <samp>-dn</samp>, <samp>-dy</samp>, <samp>-call_shared</samp>, <samp>-non_shared</samp>,
  761. <samp>-static</samp>, <samp>-N</samp>, <samp>-n</samp>, <samp>--whole-archive</samp>,
  762. <samp>--no-whole-archive</samp>, <samp>-r</samp>, <samp>-Ur</samp>,
  763. <samp>--copy-dt-needed-entries</samp>, <samp>--no-copy-dt-needed-entries</samp>,
  764. <samp>--as-needed</samp>, <samp>--no-as-needed</samp>, and <samp>-a</samp>.
  765. </p>
  766. <p>One target for this option are specifications for <samp>pkg-config</samp>. When
  767. used with the <samp>--libs</samp> option all possibly needed libraries are
  768. listed and then possibly linked with all the time. It is better to return
  769. something as follows:
  770. </p>
  771. <div class="smallexample">
  772. <pre class="smallexample">-Wl,--push-state,--as-needed -libone -libtwo -Wl,--pop-state
  773. </pre></div>
  774. <a name="index-_002d_002dpop_002dstate"></a>
  775. <a name="index-pop-state-governing-input-file-handling"></a>
  776. </dd>
  777. <dt><code>--pop-state</code></dt>
  778. <dd><p>Undoes the effect of &ndash;push-state, restores the previous values of the
  779. flags governing input file handling.
  780. </p>
  781. <a name="index-_002dq"></a>
  782. <a name="index-_002d_002demit_002drelocs"></a>
  783. <a name="index-retain-relocations-in-final-executable"></a>
  784. </dd>
  785. <dt><code>-q</code></dt>
  786. <dt><code>--emit-relocs</code></dt>
  787. <dd><p>Leave relocation sections and contents in fully linked executables.
  788. Post link analysis and optimization tools may need this information in
  789. order to perform correct modifications of executables. This results
  790. in larger executables.
  791. </p>
  792. <p>This option is currently only supported on ELF platforms.
  793. </p>
  794. <a name="index-_002d_002dforce_002ddynamic"></a>
  795. <a name="index-forcing-the-creation-of-dynamic-sections"></a>
  796. </dd>
  797. <dt><code>--force-dynamic</code></dt>
  798. <dd><p>Force the output file to have dynamic sections. This option is specific
  799. to VxWorks targets.
  800. </p>
  801. <a name="index-partial-link"></a>
  802. <a name="index-relocatable-output"></a>
  803. <a name="index-_002dr"></a>
  804. <a name="index-_002d_002drelocatable"></a>
  805. </dd>
  806. <dt><code>-r</code></dt>
  807. <dt><code>--relocatable</code></dt>
  808. <dd><p>Generate relocatable output&mdash;i.e., generate an output file that can in
  809. turn serve as input to <code>ld</code>. This is often called <em>partial
  810. linking</em>. As a side effect, in environments that support standard Unix
  811. magic numbers, this option also sets the output file&rsquo;s magic number to
  812. <code>OMAGIC</code>.
  813. If this option is not specified, an absolute file is produced. When
  814. linking C++ programs, this option <em>will not</em> resolve references to
  815. constructors; to do that, use &lsquo;<samp>-Ur</samp>&rsquo;.
  816. </p>
  817. <p>When an input file does not have the same format as the output file,
  818. partial linking is only supported if that input file does not contain any
  819. relocations. Different output formats can have further restrictions; for
  820. example some <code>a.out</code>-based formats do not support partial linking
  821. with input files in other formats at all.
  822. </p>
  823. <p>This option does the same thing as &lsquo;<samp>-i</samp>&rsquo;.
  824. </p>
  825. <a name="index-_002dR-file"></a>
  826. <a name="index-_002d_002djust_002dsymbols_003dfile"></a>
  827. <a name="index-symbol_002donly-input"></a>
  828. </dd>
  829. <dt><code>-R <var>filename</var></code></dt>
  830. <dt><code>--just-symbols=<var>filename</var></code></dt>
  831. <dd><p>Read symbol names and their addresses from <var>filename</var>, but do not
  832. relocate it or include it in the output. This allows your output file
  833. to refer symbolically to absolute locations of memory defined in other
  834. programs. You may use this option more than once.
  835. </p>
  836. <p>For compatibility with other ELF linkers, if the <samp>-R</samp> option is
  837. followed by a directory name, rather than a file name, it is treated as
  838. the <samp>-rpath</samp> option.
  839. </p>
  840. <a name="index-_002ds"></a>
  841. <a name="index-_002d_002dstrip_002dall"></a>
  842. <a name="index-strip-all-symbols"></a>
  843. </dd>
  844. <dt><code>-s</code></dt>
  845. <dt><code>--strip-all</code></dt>
  846. <dd><p>Omit all symbol information from the output file.
  847. </p>
  848. <a name="index-_002dS"></a>
  849. <a name="index-_002d_002dstrip_002ddebug"></a>
  850. <a name="index-strip-debugger-symbols"></a>
  851. </dd>
  852. <dt><code>-S</code></dt>
  853. <dt><code>--strip-debug</code></dt>
  854. <dd><p>Omit debugger symbol information (but not all symbols) from the output file.
  855. </p>
  856. <a name="index-_002d_002dstrip_002ddiscarded"></a>
  857. <a name="index-_002d_002dno_002dstrip_002ddiscarded"></a>
  858. </dd>
  859. <dt><code>--strip-discarded</code></dt>
  860. <dt><code>--no-strip-discarded</code></dt>
  861. <dd><p>Omit (or do not omit) global symbols defined in discarded sections.
  862. Enabled by default.
  863. </p>
  864. <a name="index-_002dt"></a>
  865. <a name="index-_002d_002dtrace"></a>
  866. <a name="index-input-files_002c-displaying"></a>
  867. </dd>
  868. <dt><code>-t</code></dt>
  869. <dt><code>--trace</code></dt>
  870. <dd><p>Print the names of the input files as <code>ld</code> processes them. If
  871. &lsquo;<samp>-t</samp>&rsquo; is given twice then members within archives are also printed.
  872. &lsquo;<samp>-t</samp>&rsquo; output is useful to generate a list of all the object files
  873. and scripts involved in linking, for example, when packaging files for
  874. a linker bug report.
  875. </p>
  876. <a name="index-_002dT-script"></a>
  877. <a name="index-_002d_002dscript_003dscript"></a>
  878. <a name="index-script-files"></a>
  879. </dd>
  880. <dt><code>-T <var>scriptfile</var></code></dt>
  881. <dt><code>--script=<var>scriptfile</var></code></dt>
  882. <dd><p>Use <var>scriptfile</var> as the linker script. This script replaces
  883. <code>ld</code>&rsquo;s default linker script (rather than adding to it), so
  884. <var>commandfile</var> must specify everything necessary to describe the
  885. output file. See <a href="Scripts.html#Scripts">Scripts</a>. If <var>scriptfile</var> does not exist in
  886. the current directory, <code>ld</code> looks for it in the directories
  887. specified by any preceding &lsquo;<samp>-L</samp>&rsquo; options. Multiple &lsquo;<samp>-T</samp>&rsquo;
  888. options accumulate.
  889. </p>
  890. <a name="index-_002ddT-script"></a>
  891. <a name="index-_002d_002ddefault_002dscript_003dscript"></a>
  892. <a name="index-script-files-1"></a>
  893. </dd>
  894. <dt><code>-dT <var>scriptfile</var></code></dt>
  895. <dt><code>--default-script=<var>scriptfile</var></code></dt>
  896. <dd><p>Use <var>scriptfile</var> as the default linker script. See <a href="Scripts.html#Scripts">Scripts</a>.
  897. </p>
  898. <p>This option is similar to the <samp>--script</samp> option except that
  899. processing of the script is delayed until after the rest of the
  900. command line has been processed. This allows options placed after the
  901. <samp>--default-script</samp> option on the command line to affect the
  902. behaviour of the linker script, which can be important when the linker
  903. command line cannot be directly controlled by the user. (eg because
  904. the command line is being constructed by another tool, such as
  905. &lsquo;<samp>gcc</samp>&rsquo;).
  906. </p>
  907. <a name="index-_002du-symbol"></a>
  908. <a name="index-_002d_002dundefined_003dsymbol"></a>
  909. <a name="index-undefined-symbol"></a>
  910. </dd>
  911. <dt><code>-u <var>symbol</var></code></dt>
  912. <dt><code>--undefined=<var>symbol</var></code></dt>
  913. <dd><p>Force <var>symbol</var> to be entered in the output file as an undefined
  914. symbol. Doing this may, for example, trigger linking of additional
  915. modules from standard libraries. &lsquo;<samp>-u</samp>&rsquo; may be repeated with
  916. different option arguments to enter additional undefined symbols. This
  917. option is equivalent to the <code>EXTERN</code> linker script command.
  918. </p>
  919. <p>If this option is being used to force additional modules to be pulled
  920. into the link, and if it is an error for the symbol to remain
  921. undefined, then the option <samp>--require-defined</samp> should be used
  922. instead.
  923. </p>
  924. <a name="index-_002d_002drequire_002ddefined_003dsymbol"></a>
  925. <a name="index-symbols_002c-require-defined"></a>
  926. <a name="index-defined-symbol"></a>
  927. </dd>
  928. <dt><code>--require-defined=<var>symbol</var></code></dt>
  929. <dd><p>Require that <var>symbol</var> is defined in the output file. This option
  930. is the same as option <samp>--undefined</samp> except that if <var>symbol</var>
  931. is not defined in the output file then the linker will issue an error
  932. and exit. The same effect can be achieved in a linker script by using
  933. <code>EXTERN</code>, <code>ASSERT</code> and <code>DEFINED</code> together. This option
  934. can be used multiple times to require additional symbols.
  935. </p>
  936. <a name="index-_002dUr"></a>
  937. <a name="index-constructors"></a>
  938. </dd>
  939. <dt><code>-Ur</code></dt>
  940. <dd><p>For anything other than C++ programs, this option is equivalent to
  941. &lsquo;<samp>-r</samp>&rsquo;: it generates relocatable output&mdash;i.e., an output file that can in
  942. turn serve as input to <code>ld</code>. When linking C++ programs, &lsquo;<samp>-Ur</samp>&rsquo;
  943. <em>does</em> resolve references to constructors, unlike &lsquo;<samp>-r</samp>&rsquo;.
  944. It does not work to use &lsquo;<samp>-Ur</samp>&rsquo; on files that were themselves linked
  945. with &lsquo;<samp>-Ur</samp>&rsquo;; once the constructor table has been built, it cannot
  946. be added to. Use &lsquo;<samp>-Ur</samp>&rsquo; only for the last partial link, and
  947. &lsquo;<samp>-r</samp>&rsquo; for the others.
  948. </p>
  949. <a name="index-_002d_002dorphan_002dhandling_003dMODE"></a>
  950. <a name="index-orphan-sections"></a>
  951. <a name="index-sections_002c-orphan"></a>
  952. </dd>
  953. <dt><code>--orphan-handling=<var>MODE</var></code></dt>
  954. <dd><p>Control how orphan sections are handled. An orphan section is one not
  955. specifically mentioned in a linker script. See <a href="Orphan-Sections.html#Orphan-Sections">Orphan Sections</a>.
  956. </p>
  957. <p><var>MODE</var> can have any of the following values:
  958. </p>
  959. <dl compact="compact">
  960. <dt><code>place</code></dt>
  961. <dd><p>Orphan sections are placed into a suitable output section following
  962. the strategy described in <a href="Orphan-Sections.html#Orphan-Sections">Orphan Sections</a>. The option
  963. &lsquo;<samp>--unique</samp>&rsquo; also affects how sections are placed.
  964. </p>
  965. </dd>
  966. <dt><code>discard</code></dt>
  967. <dd><p>All orphan sections are discarded, by placing them in the
  968. &lsquo;<samp>/DISCARD/</samp>&rsquo; section (see <a href="Output-Section-Discarding.html#Output-Section-Discarding">Output Section Discarding</a>).
  969. </p>
  970. </dd>
  971. <dt><code>warn</code></dt>
  972. <dd><p>The linker will place the orphan section as for <code>place</code> and also
  973. issue a warning.
  974. </p>
  975. </dd>
  976. <dt><code>error</code></dt>
  977. <dd><p>The linker will exit with an error if any orphan section is found.
  978. </p></dd>
  979. </dl>
  980. <p>The default if &lsquo;<samp>--orphan-handling</samp>&rsquo; is not given is <code>place</code>.
  981. </p>
  982. <a name="index-_002d_002dunique_005b_003dSECTION_005d"></a>
  983. </dd>
  984. <dt><code>--unique[=<var>SECTION</var>]</code></dt>
  985. <dd><p>Creates a separate output section for every input section matching
  986. <var>SECTION</var>, or if the optional wildcard <var>SECTION</var> argument is
  987. missing, for every orphan input section. An orphan section is one not
  988. specifically mentioned in a linker script. You may use this option
  989. multiple times on the command line; It prevents the normal merging of
  990. input sections with the same name, overriding output section assignments
  991. in a linker script.
  992. </p>
  993. <a name="index-_002dv"></a>
  994. <a name="index-_002dV"></a>
  995. <a name="index-_002d_002dversion"></a>
  996. <a name="index-version"></a>
  997. </dd>
  998. <dt><code>-v</code></dt>
  999. <dt><code>--version</code></dt>
  1000. <dt><code>-V</code></dt>
  1001. <dd><p>Display the version number for <code>ld</code>. The <samp>-V</samp> option also
  1002. lists the supported emulations.
  1003. </p>
  1004. <a name="index-_002dx"></a>
  1005. <a name="index-_002d_002ddiscard_002dall"></a>
  1006. <a name="index-deleting-local-symbols"></a>
  1007. </dd>
  1008. <dt><code>-x</code></dt>
  1009. <dt><code>--discard-all</code></dt>
  1010. <dd><p>Delete all local symbols.
  1011. </p>
  1012. <a name="index-_002dX"></a>
  1013. <a name="index-_002d_002ddiscard_002dlocals"></a>
  1014. <a name="index-local-symbols_002c-deleting"></a>
  1015. </dd>
  1016. <dt><code>-X</code></dt>
  1017. <dt><code>--discard-locals</code></dt>
  1018. <dd><p>Delete all temporary local symbols. (These symbols start with
  1019. system-specific local label prefixes, typically &lsquo;<samp>.L</samp>&rsquo; for ELF systems
  1020. or &lsquo;<samp>L</samp>&rsquo; for traditional a.out systems.)
  1021. </p>
  1022. <a name="index-_002dy-symbol"></a>
  1023. <a name="index-_002d_002dtrace_002dsymbol_003dsymbol"></a>
  1024. <a name="index-symbol-tracing"></a>
  1025. </dd>
  1026. <dt><code>-y <var>symbol</var></code></dt>
  1027. <dt><code>--trace-symbol=<var>symbol</var></code></dt>
  1028. <dd><p>Print the name of each linked file in which <var>symbol</var> appears. This
  1029. option may be given any number of times. On many systems it is necessary
  1030. to prepend an underscore.
  1031. </p>
  1032. <p>This option is useful when you have an undefined symbol in your link but
  1033. don&rsquo;t know where the reference is coming from.
  1034. </p>
  1035. <a name="index-_002dY-path"></a>
  1036. </dd>
  1037. <dt><code>-Y <var>path</var></code></dt>
  1038. <dd><p>Add <var>path</var> to the default library search path. This option exists
  1039. for Solaris compatibility.
  1040. </p>
  1041. <a name="index-_002dz-keyword"></a>
  1042. </dd>
  1043. <dt><code>-z <var>keyword</var></code></dt>
  1044. <dd><p>The recognized keywords are:
  1045. </p><dl compact="compact">
  1046. <dt>&lsquo;<samp>bndplt</samp>&rsquo;</dt>
  1047. <dd><p>Always generate BND prefix in PLT entries. Supported for Linux/x86_64.
  1048. </p>
  1049. </dd>
  1050. <dt>&lsquo;<samp>call-nop=prefix-addr</samp>&rsquo;</dt>
  1051. <dt>&lsquo;<samp>call-nop=suffix-nop</samp>&rsquo;</dt>
  1052. <dt>&lsquo;<samp>call-nop=prefix-<var>byte</var></samp>&rsquo;</dt>
  1053. <dt>&lsquo;<samp>call-nop=suffix-<var>byte</var></samp>&rsquo;</dt>
  1054. <dd><p>Specify the 1-byte <code>NOP</code> padding when transforming indirect call
  1055. to a locally defined function, foo, via its GOT slot.
  1056. <samp>call-nop=prefix-addr</samp> generates <code>0x67 call foo</code>.
  1057. <samp>call-nop=suffix-nop</samp> generates <code>call foo 0x90</code>.
  1058. <samp>call-nop=prefix-<var>byte</var></samp> generates <code><var>byte</var> call foo</code>.
  1059. <samp>call-nop=suffix-<var>byte</var></samp> generates <code>call foo <var>byte</var></code>.
  1060. Supported for i386 and x86_64.
  1061. </p>
  1062. </dd>
  1063. <dt>&lsquo;<samp>cet-report=none</samp>&rsquo;</dt>
  1064. <dt>&lsquo;<samp>cet-report=warning</samp>&rsquo;</dt>
  1065. <dt>&lsquo;<samp>cet-report=error</samp>&rsquo;</dt>
  1066. <dd><p>Specify how to report the missing GNU_PROPERTY_X86_FEATURE_1_IBT and
  1067. GNU_PROPERTY_X86_FEATURE_1_SHSTK properties in input .note.gnu.property
  1068. section. <samp>cet-report=none</samp>, which is the default, will make the
  1069. linker not report missing properties in input files.
  1070. <samp>cet-report=warning</samp> will make the linker issue a warning for
  1071. missing properties in input files. <samp>cet-report=error</samp> will make
  1072. the linker issue an error for missing properties in input files.
  1073. Note that <samp>ibt</samp> will turn off the missing
  1074. GNU_PROPERTY_X86_FEATURE_1_IBT property report and <samp>shstk</samp> will
  1075. turn off the missing GNU_PROPERTY_X86_FEATURE_1_SHSTK property report.
  1076. Supported for Linux/i386 and Linux/x86_64.
  1077. </p>
  1078. </dd>
  1079. <dt>&lsquo;<samp>combreloc</samp>&rsquo;</dt>
  1080. <dt>&lsquo;<samp>nocombreloc</samp>&rsquo;</dt>
  1081. <dd><p>Combine multiple dynamic relocation sections and sort to improve
  1082. dynamic symbol lookup caching. Do not do this if &lsquo;<samp>nocombreloc</samp>&rsquo;.
  1083. </p>
  1084. </dd>
  1085. <dt>&lsquo;<samp>common</samp>&rsquo;</dt>
  1086. <dt>&lsquo;<samp>nocommon</samp>&rsquo;</dt>
  1087. <dd><p>Generate common symbols with STT_COMMON type during a relocatable
  1088. link. Use STT_OBJECT type if &lsquo;<samp>nocommon</samp>&rsquo;.
  1089. </p>
  1090. </dd>
  1091. <dt>&lsquo;<samp>common-page-size=<var>value</var></samp>&rsquo;</dt>
  1092. <dd><p>Set the page size most commonly used to <var>value</var>. Memory image
  1093. layout will be optimized to minimize memory pages if the system is
  1094. using pages of this size.
  1095. </p>
  1096. </dd>
  1097. <dt>&lsquo;<samp>defs</samp>&rsquo;</dt>
  1098. <dd><p>Report unresolved symbol references from regular object files. This
  1099. is done even if the linker is creating a non-symbolic shared library.
  1100. This option is the inverse of &lsquo;<samp>-z undefs</samp>&rsquo;.
  1101. </p>
  1102. </dd>
  1103. <dt>&lsquo;<samp>dynamic-undefined-weak</samp>&rsquo;</dt>
  1104. <dt>&lsquo;<samp>nodynamic-undefined-weak</samp>&rsquo;</dt>
  1105. <dd><p>Make undefined weak symbols dynamic when building a dynamic object,
  1106. if they are referenced from a regular object file and not forced local
  1107. by symbol visibility or versioning. Do not make them dynamic if
  1108. &lsquo;<samp>nodynamic-undefined-weak</samp>&rsquo;. If neither option is given, a target
  1109. may default to either option being in force, or make some other
  1110. selection of undefined weak symbols dynamic. Not all targets support
  1111. these options.
  1112. </p>
  1113. </dd>
  1114. <dt>&lsquo;<samp>execstack</samp>&rsquo;</dt>
  1115. <dd><p>Marks the object as requiring executable stack.
  1116. </p>
  1117. </dd>
  1118. <dt>&lsquo;<samp>global</samp>&rsquo;</dt>
  1119. <dd><p>This option is only meaningful when building a shared object. It makes
  1120. the symbols defined by this shared object available for symbol resolution
  1121. of subsequently loaded libraries.
  1122. </p>
  1123. </dd>
  1124. <dt>&lsquo;<samp>globalaudit</samp>&rsquo;</dt>
  1125. <dd><p>This option is only meaningful when building a dynamic executable.
  1126. This option marks the executable as requiring global auditing by
  1127. setting the <code>DF_1_GLOBAUDIT</code> bit in the <code>DT_FLAGS_1</code> dynamic
  1128. tag. Global auditing requires that any auditing library defined via
  1129. the <samp>--depaudit</samp> or <samp>-P</samp> command-line options be run for
  1130. all dynamic objects loaded by the application.
  1131. </p>
  1132. </dd>
  1133. <dt>&lsquo;<samp>ibtplt</samp>&rsquo;</dt>
  1134. <dd><p>Generate Intel Indirect Branch Tracking (IBT) enabled PLT entries.
  1135. Supported for Linux/i386 and Linux/x86_64.
  1136. </p>
  1137. </dd>
  1138. <dt>&lsquo;<samp>ibt</samp>&rsquo;</dt>
  1139. <dd><p>Generate GNU_PROPERTY_X86_FEATURE_1_IBT in .note.gnu.property section
  1140. to indicate compatibility with IBT. This also implies <samp>ibtplt</samp>.
  1141. Supported for Linux/i386 and Linux/x86_64.
  1142. </p>
  1143. </dd>
  1144. <dt>&lsquo;<samp>initfirst</samp>&rsquo;</dt>
  1145. <dd><p>This option is only meaningful when building a shared object.
  1146. It marks the object so that its runtime initialization will occur
  1147. before the runtime initialization of any other objects brought into
  1148. the process at the same time. Similarly the runtime finalization of
  1149. the object will occur after the runtime finalization of any other
  1150. objects.
  1151. </p>
  1152. </dd>
  1153. <dt>&lsquo;<samp>interpose</samp>&rsquo;</dt>
  1154. <dd><p>Specify that the dynamic loader should modify its symbol search order
  1155. so that symbols in this shared library interpose all other shared
  1156. libraries not so marked.
  1157. </p>
  1158. </dd>
  1159. <dt>&lsquo;<samp>lazy</samp>&rsquo;</dt>
  1160. <dd><p>When generating an executable or shared library, mark it to tell the
  1161. dynamic linker to defer function call resolution to the point when
  1162. the function is called (lazy binding), rather than at load time.
  1163. Lazy binding is the default.
  1164. </p>
  1165. </dd>
  1166. <dt>&lsquo;<samp>loadfltr</samp>&rsquo;</dt>
  1167. <dd><p>Specify that the object&rsquo;s filters be processed immediately at runtime.
  1168. </p>
  1169. </dd>
  1170. <dt>&lsquo;<samp>max-page-size=<var>value</var></samp>&rsquo;</dt>
  1171. <dd><p>Set the maximum memory page size supported to <var>value</var>.
  1172. </p>
  1173. </dd>
  1174. <dt>&lsquo;<samp>muldefs</samp>&rsquo;</dt>
  1175. <dd><p>Allow multiple definitions.
  1176. </p>
  1177. </dd>
  1178. <dt>&lsquo;<samp>nocopyreloc</samp>&rsquo;</dt>
  1179. <dd><p>Disable linker generated .dynbss variables used in place of variables
  1180. defined in shared libraries. May result in dynamic text relocations.
  1181. </p>
  1182. </dd>
  1183. <dt>&lsquo;<samp>nodefaultlib</samp>&rsquo;</dt>
  1184. <dd><p>Specify that the dynamic loader search for dependencies of this object
  1185. should ignore any default library search paths.
  1186. </p>
  1187. </dd>
  1188. <dt>&lsquo;<samp>nodelete</samp>&rsquo;</dt>
  1189. <dd><p>Specify that the object shouldn&rsquo;t be unloaded at runtime.
  1190. </p>
  1191. </dd>
  1192. <dt>&lsquo;<samp>nodlopen</samp>&rsquo;</dt>
  1193. <dd><p>Specify that the object is not available to <code>dlopen</code>.
  1194. </p>
  1195. </dd>
  1196. <dt>&lsquo;<samp>nodump</samp>&rsquo;</dt>
  1197. <dd><p>Specify that the object can not be dumped by <code>dldump</code>.
  1198. </p>
  1199. </dd>
  1200. <dt>&lsquo;<samp>noexecstack</samp>&rsquo;</dt>
  1201. <dd><p>Marks the object as not requiring executable stack.
  1202. </p>
  1203. </dd>
  1204. <dt>&lsquo;<samp>noextern-protected-data</samp>&rsquo;</dt>
  1205. <dd><p>Don&rsquo;t treat protected data symbols as external when building a shared
  1206. library. This option overrides the linker backend default. It can be
  1207. used to work around incorrect relocations against protected data symbols
  1208. generated by compiler. Updates on protected data symbols by another
  1209. module aren&rsquo;t visible to the resulting shared library. Supported for
  1210. i386 and x86-64.
  1211. </p>
  1212. </dd>
  1213. <dt>&lsquo;<samp>noreloc-overflow</samp>&rsquo;</dt>
  1214. <dd><p>Disable relocation overflow check. This can be used to disable
  1215. relocation overflow check if there will be no dynamic relocation
  1216. overflow at run-time. Supported for x86_64.
  1217. </p>
  1218. </dd>
  1219. <dt>&lsquo;<samp>now</samp>&rsquo;</dt>
  1220. <dd><p>When generating an executable or shared library, mark it to tell the
  1221. dynamic linker to resolve all symbols when the program is started, or
  1222. when the shared library is loaded by dlopen, instead of deferring
  1223. function call resolution to the point when the function is first
  1224. called.
  1225. </p>
  1226. </dd>
  1227. <dt>&lsquo;<samp>origin</samp>&rsquo;</dt>
  1228. <dd><p>Specify that the object requires &lsquo;<samp>$ORIGIN</samp>&rsquo; handling in paths.
  1229. </p>
  1230. </dd>
  1231. <dt>&lsquo;<samp>relro</samp>&rsquo;</dt>
  1232. <dt>&lsquo;<samp>norelro</samp>&rsquo;</dt>
  1233. <dd><p>Create an ELF <code>PT_GNU_RELRO</code> segment header in the object. This
  1234. specifies a memory segment that should be made read-only after
  1235. relocation, if supported. Specifying &lsquo;<samp>common-page-size</samp>&rsquo; smaller
  1236. than the system page size will render this protection ineffective.
  1237. Don&rsquo;t create an ELF <code>PT_GNU_RELRO</code> segment if &lsquo;<samp>norelro</samp>&rsquo;.
  1238. </p>
  1239. </dd>
  1240. <dt>&lsquo;<samp>separate-code</samp>&rsquo;</dt>
  1241. <dt>&lsquo;<samp>noseparate-code</samp>&rsquo;</dt>
  1242. <dd><p>Create separate code <code>PT_LOAD</code> segment header in the object. This
  1243. specifies a memory segment that should contain only instructions and must
  1244. be in wholly disjoint pages from any other data. Don&rsquo;t create separate
  1245. code <code>PT_LOAD</code> segment if &lsquo;<samp>noseparate-code</samp>&rsquo; is used.
  1246. </p>
  1247. </dd>
  1248. <dt>&lsquo;<samp>shstk</samp>&rsquo;</dt>
  1249. <dd><p>Generate GNU_PROPERTY_X86_FEATURE_1_SHSTK in .note.gnu.property section
  1250. to indicate compatibility with Intel Shadow Stack. Supported for
  1251. Linux/i386 and Linux/x86_64.
  1252. </p>
  1253. </dd>
  1254. <dt>&lsquo;<samp>stack-size=<var>value</var></samp>&rsquo;</dt>
  1255. <dd><p>Specify a stack size for an ELF <code>PT_GNU_STACK</code> segment.
  1256. Specifying zero will override any default non-zero sized
  1257. <code>PT_GNU_STACK</code> segment creation.
  1258. </p>
  1259. </dd>
  1260. <dt>&lsquo;<samp>start-stop-visibility=<var>value</var></samp>&rsquo;</dt>
  1261. <dd><a name="index-visibility"></a>
  1262. <a name="index-ELF-symbol-visibility"></a>
  1263. <p>Specify the ELF symbol visibility for synthesized
  1264. <code>__start_SECNAME</code> and <code>__stop_SECNAME</code> symbols (see <a href="Input-Section-Example.html#Input-Section-Example">Input Section Example</a>). <var>value</var> must be exactly &lsquo;<samp>default</samp>&rsquo;,
  1265. &lsquo;<samp>internal</samp>&rsquo;, &lsquo;<samp>hidden</samp>&rsquo;, or &lsquo;<samp>protected</samp>&rsquo;. If no &lsquo;<samp>-z
  1266. start-stop-visibility</samp>&rsquo; option is given, &lsquo;<samp>protected</samp>&rsquo; is used for
  1267. compatibility with historical practice. However, it&rsquo;s highly
  1268. recommended to use &lsquo;<samp>-z start-stop-visibility=hidden</samp>&rsquo; in new
  1269. programs and shared libraries so that these symbols are not exported
  1270. between shared objects, which is not usually what&rsquo;s intended.
  1271. </p>
  1272. </dd>
  1273. <dt>&lsquo;<samp>text</samp>&rsquo;</dt>
  1274. <dt>&lsquo;<samp>notext</samp>&rsquo;</dt>
  1275. <dt>&lsquo;<samp>textoff</samp>&rsquo;</dt>
  1276. <dd><p>Report an error if DT_TEXTREL is set, i.e., if the position-independent
  1277. or shared object has dynamic relocations in read-only sections. Don&rsquo;t
  1278. report an error if &lsquo;<samp>notext</samp>&rsquo; or &lsquo;<samp>textoff</samp>&rsquo;.
  1279. </p>
  1280. </dd>
  1281. <dt>&lsquo;<samp>undefs</samp>&rsquo;</dt>
  1282. <dd><p>Do not report unresolved symbol references from regular object files,
  1283. either when creating an executable, or when creating a shared library.
  1284. This option is the inverse of &lsquo;<samp>-z defs</samp>&rsquo;.
  1285. </p>
  1286. </dd>
  1287. </dl>
  1288. <p>Other keywords are ignored for Solaris compatibility.
  1289. </p>
  1290. <a name="index-_002d_0028"></a>
  1291. <a name="index-groups-of-archives"></a>
  1292. </dd>
  1293. <dt><code>-( <var>archives</var> -)</code></dt>
  1294. <dt><code>--start-group <var>archives</var> --end-group</code></dt>
  1295. <dd><p>The <var>archives</var> should be a list of archive files. They may be
  1296. either explicit file names, or &lsquo;<samp>-l</samp>&rsquo; options.
  1297. </p>
  1298. <p>The specified archives are searched repeatedly until no new undefined
  1299. references are created. Normally, an archive is searched only once in
  1300. the order that it is specified on the command line. If a symbol in that
  1301. archive is needed to resolve an undefined symbol referred to by an
  1302. object in an archive that appears later on the command line, the linker
  1303. would not be able to resolve that reference. By grouping the archives,
  1304. they will all be searched repeatedly until all possible references are
  1305. resolved.
  1306. </p>
  1307. <p>Using this option has a significant performance cost. It is best to use
  1308. it only when there are unavoidable circular references between two or
  1309. more archives.
  1310. </p>
  1311. <a name="index-_002d_002daccept_002dunknown_002dinput_002darch"></a>
  1312. <a name="index-_002d_002dno_002daccept_002dunknown_002dinput_002darch"></a>
  1313. </dd>
  1314. <dt><code>--accept-unknown-input-arch</code></dt>
  1315. <dt><code>--no-accept-unknown-input-arch</code></dt>
  1316. <dd><p>Tells the linker to accept input files whose architecture cannot be
  1317. recognised. The assumption is that the user knows what they are doing
  1318. and deliberately wants to link in these unknown input files. This was
  1319. the default behaviour of the linker, before release 2.14. The default
  1320. behaviour from release 2.14 onwards is to reject such input files, and
  1321. so the &lsquo;<samp>--accept-unknown-input-arch</samp>&rsquo; option has been added to
  1322. restore the old behaviour.
  1323. </p>
  1324. <a name="index-_002d_002das_002dneeded"></a>
  1325. <a name="index-_002d_002dno_002das_002dneeded"></a>
  1326. </dd>
  1327. <dt><code>--as-needed</code></dt>
  1328. <dt><code>--no-as-needed</code></dt>
  1329. <dd><p>This option affects ELF DT_NEEDED tags for dynamic libraries mentioned
  1330. on the command line after the <samp>--as-needed</samp> option. Normally
  1331. the linker will add a DT_NEEDED tag for each dynamic library mentioned
  1332. on the command line, regardless of whether the library is actually
  1333. needed or not. <samp>--as-needed</samp> causes a DT_NEEDED tag to only be
  1334. emitted for a library that <em>at that point in the link</em> satisfies a
  1335. non-weak undefined symbol reference from a regular object file or, if
  1336. the library is not found in the DT_NEEDED lists of other needed libraries, a
  1337. non-weak undefined symbol reference from another needed dynamic library.
  1338. Object files or libraries appearing on the command line <em>after</em>
  1339. the library in question do not affect whether the library is seen as
  1340. needed. This is similar to the rules for extraction of object files
  1341. from archives. <samp>--no-as-needed</samp> restores the default behaviour.
  1342. </p>
  1343. <a name="index-_002d_002dadd_002dneeded"></a>
  1344. <a name="index-_002d_002dno_002dadd_002dneeded"></a>
  1345. </dd>
  1346. <dt><code>--add-needed</code></dt>
  1347. <dt><code>--no-add-needed</code></dt>
  1348. <dd><p>These two options have been deprecated because of the similarity of
  1349. their names to the <samp>--as-needed</samp> and <samp>--no-as-needed</samp>
  1350. options. They have been replaced by <samp>--copy-dt-needed-entries</samp>
  1351. and <samp>--no-copy-dt-needed-entries</samp>.
  1352. </p>
  1353. <a name="index-_002dassert-keyword"></a>
  1354. </dd>
  1355. <dt><code>-assert <var>keyword</var></code></dt>
  1356. <dd><p>This option is ignored for SunOS compatibility.
  1357. </p>
  1358. <a name="index-_002dBdynamic"></a>
  1359. <a name="index-_002ddy"></a>
  1360. <a name="index-_002dcall_005fshared"></a>
  1361. </dd>
  1362. <dt><code>-Bdynamic</code></dt>
  1363. <dt><code>-dy</code></dt>
  1364. <dt><code>-call_shared</code></dt>
  1365. <dd><p>Link against dynamic libraries. This is only meaningful on platforms
  1366. for which shared libraries are supported. This option is normally the
  1367. default on such platforms. The different variants of this option are
  1368. for compatibility with various systems. You may use this option
  1369. multiple times on the command line: it affects library searching for
  1370. <samp>-l</samp> options which follow it.
  1371. </p>
  1372. <a name="index-_002dBgroup"></a>
  1373. </dd>
  1374. <dt><code>-Bgroup</code></dt>
  1375. <dd><p>Set the <code>DF_1_GROUP</code> flag in the <code>DT_FLAGS_1</code> entry in the dynamic
  1376. section. This causes the runtime linker to handle lookups in this
  1377. object and its dependencies to be performed only inside the group.
  1378. <samp>--unresolved-symbols=report-all</samp> is implied. This option is
  1379. only meaningful on ELF platforms which support shared libraries.
  1380. </p>
  1381. <a name="index-_002dBstatic"></a>
  1382. <a name="index-_002ddn"></a>
  1383. <a name="index-_002dnon_005fshared"></a>
  1384. <a name="index-_002dstatic"></a>
  1385. </dd>
  1386. <dt><code>-Bstatic</code></dt>
  1387. <dt><code>-dn</code></dt>
  1388. <dt><code>-non_shared</code></dt>
  1389. <dt><code>-static</code></dt>
  1390. <dd><p>Do not link against shared libraries. This is only meaningful on
  1391. platforms for which shared libraries are supported. The different
  1392. variants of this option are for compatibility with various systems. You
  1393. may use this option multiple times on the command line: it affects
  1394. library searching for <samp>-l</samp> options which follow it. This
  1395. option also implies <samp>--unresolved-symbols=report-all</samp>. This
  1396. option can be used with <samp>-shared</samp>. Doing so means that a
  1397. shared library is being created but that all of the library&rsquo;s external
  1398. references must be resolved by pulling in entries from static
  1399. libraries.
  1400. </p>
  1401. <a name="index-_002dBsymbolic"></a>
  1402. </dd>
  1403. <dt><code>-Bsymbolic</code></dt>
  1404. <dd><p>When creating a shared library, bind references to global symbols to the
  1405. definition within the shared library, if any. Normally, it is possible
  1406. for a program linked against a shared library to override the definition
  1407. within the shared library. This option is only meaningful on ELF
  1408. platforms which support shared libraries.
  1409. </p>
  1410. <a name="index-_002dBsymbolic_002dfunctions"></a>
  1411. </dd>
  1412. <dt><code>-Bsymbolic-functions</code></dt>
  1413. <dd><p>When creating a shared library, bind references to global function
  1414. symbols to the definition within the shared library, if any.
  1415. This option is only meaningful on ELF platforms which support shared
  1416. libraries.
  1417. </p>
  1418. <a name="index-_002d_002ddynamic_002dlist_003ddynamic_002dlist_002dfile"></a>
  1419. </dd>
  1420. <dt><code>--dynamic-list=<var>dynamic-list-file</var></code></dt>
  1421. <dd><p>Specify the name of a dynamic list file to the linker. This is
  1422. typically used when creating shared libraries to specify a list of
  1423. global symbols whose references shouldn&rsquo;t be bound to the definition
  1424. within the shared library, or creating dynamically linked executables
  1425. to specify a list of symbols which should be added to the symbol table
  1426. in the executable. This option is only meaningful on ELF platforms
  1427. which support shared libraries.
  1428. </p>
  1429. <p>The format of the dynamic list is the same as the version node without
  1430. scope and node name. See <a href="VERSION.html#VERSION">VERSION</a> for more information.
  1431. </p>
  1432. <a name="index-_002d_002ddynamic_002dlist_002ddata"></a>
  1433. </dd>
  1434. <dt><code>--dynamic-list-data</code></dt>
  1435. <dd><p>Include all global data symbols to the dynamic list.
  1436. </p>
  1437. <a name="index-_002d_002ddynamic_002dlist_002dcpp_002dnew"></a>
  1438. </dd>
  1439. <dt><code>--dynamic-list-cpp-new</code></dt>
  1440. <dd><p>Provide the builtin dynamic list for C++ operator new and delete. It
  1441. is mainly useful for building shared libstdc++.
  1442. </p>
  1443. <a name="index-_002d_002ddynamic_002dlist_002dcpp_002dtypeinfo"></a>
  1444. </dd>
  1445. <dt><code>--dynamic-list-cpp-typeinfo</code></dt>
  1446. <dd><p>Provide the builtin dynamic list for C++ runtime type identification.
  1447. </p>
  1448. <a name="index-_002d_002dcheck_002dsections"></a>
  1449. <a name="index-_002d_002dno_002dcheck_002dsections"></a>
  1450. </dd>
  1451. <dt><code>--check-sections</code></dt>
  1452. <dt><code>--no-check-sections</code></dt>
  1453. <dd><p>Asks the linker <em>not</em> to check section addresses after they have
  1454. been assigned to see if there are any overlaps. Normally the linker will
  1455. perform this check, and if it finds any overlaps it will produce
  1456. suitable error messages. The linker does know about, and does make
  1457. allowances for sections in overlays. The default behaviour can be
  1458. restored by using the command-line switch <samp>--check-sections</samp>.
  1459. Section overlap is not usually checked for relocatable links. You can
  1460. force checking in that case by using the <samp>--check-sections</samp>
  1461. option.
  1462. </p>
  1463. <a name="index-_002d_002dcopy_002ddt_002dneeded_002dentries"></a>
  1464. <a name="index-_002d_002dno_002dcopy_002ddt_002dneeded_002dentries"></a>
  1465. </dd>
  1466. <dt><code>--copy-dt-needed-entries</code></dt>
  1467. <dt><code>--no-copy-dt-needed-entries</code></dt>
  1468. <dd><p>This option affects the treatment of dynamic libraries referred to
  1469. by DT_NEEDED tags <em>inside</em> ELF dynamic libraries mentioned on the
  1470. command line. Normally the linker won&rsquo;t add a DT_NEEDED tag to the
  1471. output binary for each library mentioned in a DT_NEEDED tag in an
  1472. input dynamic library. With <samp>--copy-dt-needed-entries</samp>
  1473. specified on the command line however any dynamic libraries that
  1474. follow it will have their DT_NEEDED entries added. The default
  1475. behaviour can be restored with <samp>--no-copy-dt-needed-entries</samp>.
  1476. </p>
  1477. <p>This option also has an effect on the resolution of symbols in dynamic
  1478. libraries. With <samp>--copy-dt-needed-entries</samp> dynamic libraries
  1479. mentioned on the command line will be recursively searched, following
  1480. their DT_NEEDED tags to other libraries, in order to resolve symbols
  1481. required by the output binary. With the default setting however
  1482. the searching of dynamic libraries that follow it will stop with the
  1483. dynamic library itself. No DT_NEEDED links will be traversed to resolve
  1484. symbols.
  1485. </p>
  1486. <a name="index-cross-reference-table"></a>
  1487. <a name="index-_002d_002dcref"></a>
  1488. </dd>
  1489. <dt><code>--cref</code></dt>
  1490. <dd><p>Output a cross reference table. If a linker map file is being
  1491. generated, the cross reference table is printed to the map file.
  1492. Otherwise, it is printed on the standard output.
  1493. </p>
  1494. <p>The format of the table is intentionally simple, so that it may be
  1495. easily processed by a script if necessary. The symbols are printed out,
  1496. sorted by name. For each symbol, a list of file names is given. If the
  1497. symbol is defined, the first file listed is the location of the
  1498. definition. If the symbol is defined as a common value then any files
  1499. where this happens appear next. Finally any files that reference the
  1500. symbol are listed.
  1501. </p>
  1502. <a name="index-common-allocation-1"></a>
  1503. <a name="index-_002d_002dno_002ddefine_002dcommon"></a>
  1504. </dd>
  1505. <dt><code>--no-define-common</code></dt>
  1506. <dd><p>This option inhibits the assignment of addresses to common symbols.
  1507. The script command <code>INHIBIT_COMMON_ALLOCATION</code> has the same effect.
  1508. See <a href="Miscellaneous-Commands.html#Miscellaneous-Commands">Miscellaneous Commands</a>.
  1509. </p>
  1510. <p>The &lsquo;<samp>--no-define-common</samp>&rsquo; option allows decoupling
  1511. the decision to assign addresses to Common symbols from the choice
  1512. of the output file type; otherwise a non-Relocatable output type
  1513. forces assigning addresses to Common symbols.
  1514. Using &lsquo;<samp>--no-define-common</samp>&rsquo; allows Common symbols that are referenced
  1515. from a shared library to be assigned addresses only in the main program.
  1516. This eliminates the unused duplicate space in the shared library,
  1517. and also prevents any possible confusion over resolving to the wrong
  1518. duplicate when there are many dynamic modules with specialized search
  1519. paths for runtime symbol resolution.
  1520. </p>
  1521. <a name="index-group-allocation-in-linker-script"></a>
  1522. <a name="index-section-groups"></a>
  1523. <a name="index-COMDAT"></a>
  1524. <a name="index-_002d_002dforce_002dgroup_002dallocation"></a>
  1525. </dd>
  1526. <dt><code>--force-group-allocation</code></dt>
  1527. <dd><p>This option causes the linker to place section group members like
  1528. normal input sections, and to delete the section groups. This is the
  1529. default behaviour for a final link but this option can be used to
  1530. change the behaviour of a relocatable link (&lsquo;<samp>-r</samp>&rsquo;). The script
  1531. command <code>FORCE_GROUP_ALLOCATION</code> has the same
  1532. effect. See <a href="Miscellaneous-Commands.html#Miscellaneous-Commands">Miscellaneous Commands</a>.
  1533. </p>
  1534. <a name="index-symbols_002c-from-command-line"></a>
  1535. <a name="index-_002d_002ddefsym_003dsymbol_003dexp"></a>
  1536. </dd>
  1537. <dt><code>--defsym=<var>symbol</var>=<var>expression</var></code></dt>
  1538. <dd><p>Create a global symbol in the output file, containing the absolute
  1539. address given by <var>expression</var>. You may use this option as many
  1540. times as necessary to define multiple symbols in the command line. A
  1541. limited form of arithmetic is supported for the <var>expression</var> in this
  1542. context: you may give a hexadecimal constant or the name of an existing
  1543. symbol, or use <code>+</code> and <code>-</code> to add or subtract hexadecimal
  1544. constants or symbols. If you need more elaborate expressions, consider
  1545. using the linker command language from a script (see <a href="Assignments.html#Assignments">Assignments</a>).
  1546. <em>Note:</em> there should be no white space between <var>symbol</var>, the
  1547. equals sign (&ldquo;<tt class="key">=</tt>&rdquo;), and <var>expression</var>.
  1548. </p>
  1549. <a name="index-demangling_002c-from-command-line"></a>
  1550. <a name="index-_002d_002ddemangle_005b_003dstyle_005d"></a>
  1551. <a name="index-_002d_002dno_002ddemangle"></a>
  1552. </dd>
  1553. <dt><code>--demangle[=<var>style</var>]</code></dt>
  1554. <dt><code>--no-demangle</code></dt>
  1555. <dd><p>These options control whether to demangle symbol names in error messages
  1556. and other output. When the linker is told to demangle, it tries to
  1557. present symbol names in a readable fashion: it strips leading
  1558. underscores if they are used by the object file format, and converts C++
  1559. mangled symbol names into user readable names. Different compilers have
  1560. different mangling styles. The optional demangling style argument can be used
  1561. to choose an appropriate demangling style for your compiler. The linker will
  1562. demangle by default unless the environment variable &lsquo;<samp>COLLECT_NO_DEMANGLE</samp>&rsquo;
  1563. is set. These options may be used to override the default.
  1564. </p>
  1565. <a name="index-dynamic-linker_002c-from-command-line"></a>
  1566. <a name="index-_002dIfile"></a>
  1567. <a name="index-_002d_002ddynamic_002dlinker_003dfile"></a>
  1568. </dd>
  1569. <dt><code>-I<var>file</var></code></dt>
  1570. <dt><code>--dynamic-linker=<var>file</var></code></dt>
  1571. <dd><p>Set the name of the dynamic linker. This is only meaningful when
  1572. generating dynamically linked ELF executables. The default dynamic
  1573. linker is normally correct; don&rsquo;t use this unless you know what you are
  1574. doing.
  1575. </p>
  1576. <a name="index-_002d_002dno_002ddynamic_002dlinker"></a>
  1577. </dd>
  1578. <dt><code>--no-dynamic-linker</code></dt>
  1579. <dd><p>When producing an executable file, omit the request for a dynamic
  1580. linker to be used at load-time. This is only meaningful for ELF
  1581. executables that contain dynamic relocations, and usually requires
  1582. entry point code that is capable of processing these relocations.
  1583. </p>
  1584. <a name="index-_002d_002dembedded_002drelocs"></a>
  1585. </dd>
  1586. <dt><code>--embedded-relocs</code></dt>
  1587. <dd><p>This option is similar to the <samp>--emit-relocs</samp> option except
  1588. that the relocs are stored in a target-specific section. This option
  1589. is only supported by the &lsquo;<samp>BFIN</samp>&rsquo;, &lsquo;<samp>CR16</samp>&rsquo; and <em>M68K</em>
  1590. targets.
  1591. </p>
  1592. <a name="index-_002d_002ddisable_002dmultiple_002dabs_002ddefs"></a>
  1593. </dd>
  1594. <dt><code>--disable-multiple-abs-defs</code></dt>
  1595. <dd><p>Do not allow multiple definitions with symbols included
  1596. in filename invoked by -R or &ndash;just-symbols
  1597. </p>
  1598. <a name="index-_002d_002dfatal_002dwarnings"></a>
  1599. <a name="index-_002d_002dno_002dfatal_002dwarnings"></a>
  1600. </dd>
  1601. <dt><code>--fatal-warnings</code></dt>
  1602. <dt><code>--no-fatal-warnings</code></dt>
  1603. <dd><p>Treat all warnings as errors. The default behaviour can be restored
  1604. with the option <samp>--no-fatal-warnings</samp>.
  1605. </p>
  1606. <a name="index-_002d_002dforce_002dexe_002dsuffix"></a>
  1607. </dd>
  1608. <dt><code>--force-exe-suffix</code></dt>
  1609. <dd><p>Make sure that an output file has a .exe suffix.
  1610. </p>
  1611. <p>If a successfully built fully linked output file does not have a
  1612. <code>.exe</code> or <code>.dll</code> suffix, this option forces the linker to copy
  1613. the output file to one of the same name with a <code>.exe</code> suffix. This
  1614. option is useful when using unmodified Unix makefiles on a Microsoft
  1615. Windows host, since some versions of Windows won&rsquo;t run an image unless
  1616. it ends in a <code>.exe</code> suffix.
  1617. </p>
  1618. <a name="index-_002d_002dgc_002dsections"></a>
  1619. <a name="index-_002d_002dno_002dgc_002dsections"></a>
  1620. <a name="index-garbage-collection"></a>
  1621. </dd>
  1622. <dt><code>--gc-sections</code></dt>
  1623. <dt><code>--no-gc-sections</code></dt>
  1624. <dd><p>Enable garbage collection of unused input sections. It is ignored on
  1625. targets that do not support this option. The default behaviour (of not
  1626. performing this garbage collection) can be restored by specifying
  1627. &lsquo;<samp>--no-gc-sections</samp>&rsquo; on the command line. Note that garbage
  1628. collection for COFF and PE format targets is supported, but the
  1629. implementation is currently considered to be experimental.
  1630. </p>
  1631. <p>&lsquo;<samp>--gc-sections</samp>&rsquo; decides which input sections are used by
  1632. examining symbols and relocations. The section containing the entry
  1633. symbol and all sections containing symbols undefined on the
  1634. command-line will be kept, as will sections containing symbols
  1635. referenced by dynamic objects. Note that when building shared
  1636. libraries, the linker must assume that any visible symbol is
  1637. referenced. Once this initial set of sections has been determined,
  1638. the linker recursively marks as used any section referenced by their
  1639. relocations. See &lsquo;<samp>--entry</samp>&rsquo;, &lsquo;<samp>--undefined</samp>&rsquo;, and
  1640. &lsquo;<samp>--gc-keep-exported</samp>&rsquo;.
  1641. </p>
  1642. <p>This option can be set when doing a partial link (enabled with option
  1643. &lsquo;<samp>-r</samp>&rsquo;). In this case the root of symbols kept must be explicitly
  1644. specified either by one of the options &lsquo;<samp>--entry</samp>&rsquo;,
  1645. &lsquo;<samp>--undefined</samp>&rsquo;, or &lsquo;<samp>--gc-keep-exported</samp>&rsquo; or by a <code>ENTRY</code>
  1646. command in the linker script.
  1647. </p>
  1648. <a name="index-_002d_002dprint_002dgc_002dsections"></a>
  1649. <a name="index-_002d_002dno_002dprint_002dgc_002dsections"></a>
  1650. <a name="index-garbage-collection-1"></a>
  1651. </dd>
  1652. <dt><code>--print-gc-sections</code></dt>
  1653. <dt><code>--no-print-gc-sections</code></dt>
  1654. <dd><p>List all sections removed by garbage collection. The listing is
  1655. printed on stderr. This option is only effective if garbage
  1656. collection has been enabled via the &lsquo;<samp>--gc-sections</samp>&rsquo;) option. The
  1657. default behaviour (of not listing the sections that are removed) can
  1658. be restored by specifying &lsquo;<samp>--no-print-gc-sections</samp>&rsquo; on the command
  1659. line.
  1660. </p>
  1661. <a name="index-_002d_002dgc_002dkeep_002dexported"></a>
  1662. <a name="index-garbage-collection-2"></a>
  1663. </dd>
  1664. <dt><code>--gc-keep-exported</code></dt>
  1665. <dd><p>When &lsquo;<samp>--gc-sections</samp>&rsquo; is enabled, this option prevents garbage
  1666. collection of unused input sections that contain global symbols having
  1667. default or protected visibility. This option is intended to be used for
  1668. executables where unreferenced sections would otherwise be garbage
  1669. collected regardless of the external visibility of contained symbols.
  1670. Note that this option has no effect when linking shared objects since
  1671. it is already the default behaviour. This option is only supported for
  1672. ELF format targets.
  1673. </p>
  1674. <a name="index-_002d_002dprint_002doutput_002dformat"></a>
  1675. <a name="index-output-format"></a>
  1676. </dd>
  1677. <dt><code>--print-output-format</code></dt>
  1678. <dd><p>Print the name of the default output format (perhaps influenced by
  1679. other command-line options). This is the string that would appear
  1680. in an <code>OUTPUT_FORMAT</code> linker script command (see <a href="File-Commands.html#File-Commands">File Commands</a>).
  1681. </p>
  1682. <a name="index-_002d_002dprint_002dmemory_002dusage"></a>
  1683. <a name="index-memory-usage"></a>
  1684. </dd>
  1685. <dt><code>--print-memory-usage</code></dt>
  1686. <dd><p>Print used size, total size and used size of memory regions created with
  1687. the <a href="MEMORY.html#MEMORY">MEMORY</a> command. This is useful on embedded targets to have a
  1688. quick view of amount of free memory. The format of the output has one
  1689. headline and one line per region. It is both human readable and easily
  1690. parsable by tools. Here is an example of an output:
  1691. </p>
  1692. <div class="smallexample">
  1693. <pre class="smallexample">Memory region Used Size Region Size %age Used
  1694. ROM: 256 KB 1 MB 25.00%
  1695. RAM: 32 B 2 GB 0.00%
  1696. </pre></div>
  1697. <a name="index-help"></a>
  1698. <a name="index-usage"></a>
  1699. <a name="index-_002d_002dhelp"></a>
  1700. </dd>
  1701. <dt><code>--help</code></dt>
  1702. <dd><p>Print a summary of the command-line options on the standard output and exit.
  1703. </p>
  1704. <a name="index-_002d_002dtarget_002dhelp"></a>
  1705. </dd>
  1706. <dt><code>--target-help</code></dt>
  1707. <dd><p>Print a summary of all target-specific options on the standard output and exit.
  1708. </p>
  1709. <a name="index-_002dMap_003dmapfile"></a>
  1710. </dd>
  1711. <dt><code>-Map=<var>mapfile</var></code></dt>
  1712. <dd><p>Print a link map to the file <var>mapfile</var>. See the description of the
  1713. <samp>-M</samp> option, above. Specifying a directory as <var>mapfile</var>
  1714. causes the linker map to be written into a file inside the directory.
  1715. The name of the file is based upon the <var>output</var> filename with
  1716. <code>.map</code> appended.
  1717. </p>
  1718. <a name="index-memory-usage-1"></a>
  1719. <a name="index-_002d_002dno_002dkeep_002dmemory"></a>
  1720. </dd>
  1721. <dt><code>--no-keep-memory</code></dt>
  1722. <dd><p><code>ld</code> normally optimizes for speed over memory usage by caching the
  1723. symbol tables of input files in memory. This option tells <code>ld</code> to
  1724. instead optimize for memory usage, by rereading the symbol tables as
  1725. necessary. This may be required if <code>ld</code> runs out of memory space
  1726. while linking a large executable.
  1727. </p>
  1728. <a name="index-_002d_002dno_002dundefined"></a>
  1729. <a name="index-_002dz-defs"></a>
  1730. <a name="index-_002dz-undefs"></a>
  1731. </dd>
  1732. <dt><code>--no-undefined</code></dt>
  1733. <dt><code>-z defs</code></dt>
  1734. <dd><p>Report unresolved symbol references from regular object files. This
  1735. is done even if the linker is creating a non-symbolic shared library.
  1736. The switch <samp>--[no-]allow-shlib-undefined</samp> controls the
  1737. behaviour for reporting unresolved references found in shared
  1738. libraries being linked in.
  1739. </p>
  1740. <p>The effects of this option can be reverted by using <code>-z undefs</code>.
  1741. </p>
  1742. <a name="index-_002d_002dallow_002dmultiple_002ddefinition"></a>
  1743. <a name="index-_002dz-muldefs"></a>
  1744. </dd>
  1745. <dt><code>--allow-multiple-definition</code></dt>
  1746. <dt><code>-z muldefs</code></dt>
  1747. <dd><p>Normally when a symbol is defined multiple times, the linker will
  1748. report a fatal error. These options allow multiple definitions and the
  1749. first definition will be used.
  1750. </p>
  1751. <a name="index-_002d_002dallow_002dshlib_002dundefined"></a>
  1752. <a name="index-_002d_002dno_002dallow_002dshlib_002dundefined"></a>
  1753. </dd>
  1754. <dt><code>--allow-shlib-undefined</code></dt>
  1755. <dt><code>--no-allow-shlib-undefined</code></dt>
  1756. <dd><p>Allows or disallows undefined symbols in shared libraries.
  1757. This switch is similar to <samp>--no-undefined</samp> except that it
  1758. determines the behaviour when the undefined symbols are in a
  1759. shared library rather than a regular object file. It does not affect
  1760. how undefined symbols in regular object files are handled.
  1761. </p>
  1762. <p>The default behaviour is to report errors for any undefined symbols
  1763. referenced in shared libraries if the linker is being used to create
  1764. an executable, but to allow them if the linker is being used to create
  1765. a shared library.
  1766. </p>
  1767. <p>The reasons for allowing undefined symbol references in shared
  1768. libraries specified at link time are that:
  1769. </p>
  1770. <ul>
  1771. <li> A shared library specified at link time may not be the same as the one
  1772. that is available at load time, so the symbol might actually be
  1773. resolvable at load time.
  1774. </li><li> There are some operating systems, eg BeOS and HPPA, where undefined
  1775. symbols in shared libraries are normal.
  1776. <p>The BeOS kernel for example patches shared libraries at load time to
  1777. select whichever function is most appropriate for the current
  1778. architecture. This is used, for example, to dynamically select an
  1779. appropriate memset function.
  1780. </p></li></ul>
  1781. <a name="index-_002d_002dno_002dundefined_002dversion"></a>
  1782. </dd>
  1783. <dt><code>--no-undefined-version</code></dt>
  1784. <dd><p>Normally when a symbol has an undefined version, the linker will ignore
  1785. it. This option disallows symbols with undefined version and a fatal error
  1786. will be issued instead.
  1787. </p>
  1788. <a name="index-_002d_002ddefault_002dsymver"></a>
  1789. </dd>
  1790. <dt><code>--default-symver</code></dt>
  1791. <dd><p>Create and use a default symbol version (the soname) for unversioned
  1792. exported symbols.
  1793. </p>
  1794. <a name="index-_002d_002ddefault_002dimported_002dsymver"></a>
  1795. </dd>
  1796. <dt><code>--default-imported-symver</code></dt>
  1797. <dd><p>Create and use a default symbol version (the soname) for unversioned
  1798. imported symbols.
  1799. </p>
  1800. <a name="index-_002d_002dno_002dwarn_002dmismatch"></a>
  1801. </dd>
  1802. <dt><code>--no-warn-mismatch</code></dt>
  1803. <dd><p>Normally <code>ld</code> will give an error if you try to link together input
  1804. files that are mismatched for some reason, perhaps because they have
  1805. been compiled for different processors or for different endiannesses.
  1806. This option tells <code>ld</code> that it should silently permit such possible
  1807. errors. This option should only be used with care, in cases when you
  1808. have taken some special action that ensures that the linker errors are
  1809. inappropriate.
  1810. </p>
  1811. <a name="index-_002d_002dno_002dwarn_002dsearch_002dmismatch"></a>
  1812. </dd>
  1813. <dt><code>--no-warn-search-mismatch</code></dt>
  1814. <dd><p>Normally <code>ld</code> will give a warning if it finds an incompatible
  1815. library during a library search. This option silences the warning.
  1816. </p>
  1817. <a name="index-_002d_002dno_002dwhole_002darchive"></a>
  1818. </dd>
  1819. <dt><code>--no-whole-archive</code></dt>
  1820. <dd><p>Turn off the effect of the <samp>--whole-archive</samp> option for subsequent
  1821. archive files.
  1822. </p>
  1823. <a name="index-output-file-after-errors"></a>
  1824. <a name="index-_002d_002dnoinhibit_002dexec"></a>
  1825. </dd>
  1826. <dt><code>--noinhibit-exec</code></dt>
  1827. <dd><p>Retain the executable output file whenever it is still usable.
  1828. Normally, the linker will not produce an output file if it encounters
  1829. errors during the link process; it exits without writing an output file
  1830. when it issues any error whatsoever.
  1831. </p>
  1832. <a name="index-_002dnostdlib"></a>
  1833. </dd>
  1834. <dt><code>-nostdlib</code></dt>
  1835. <dd><p>Only search library directories explicitly specified on the
  1836. command line. Library directories specified in linker scripts
  1837. (including linker scripts specified on the command line) are ignored.
  1838. </p>
  1839. <a name="index-_002d_002doformat_003doutput_002dformat"></a>
  1840. </dd>
  1841. <dt><code>--oformat=<var>output-format</var></code></dt>
  1842. <dd><p><code>ld</code> may be configured to support more than one kind of object
  1843. file. If your <code>ld</code> is configured this way, you can use the
  1844. &lsquo;<samp>--oformat</samp>&rsquo; option to specify the binary format for the output
  1845. object file. Even when <code>ld</code> is configured to support alternative
  1846. object formats, you don&rsquo;t usually need to specify this, as <code>ld</code>
  1847. should be configured to produce as a default output format the most
  1848. usual format on each machine. <var>output-format</var> is a text string, the
  1849. name of a particular format supported by the BFD libraries. (You can
  1850. list the available binary formats with &lsquo;<samp>objdump -i</samp>&rsquo;.) The script
  1851. command <code>OUTPUT_FORMAT</code> can also specify the output format, but
  1852. this option overrides it. See <a href="BFD.html#BFD">BFD</a>.
  1853. </p>
  1854. <a name="index-_002d_002dout_002dimplib"></a>
  1855. </dd>
  1856. <dt><code>--out-implib <var>file</var></code></dt>
  1857. <dd><p>Create an import library in <var>file</var> corresponding to the executable
  1858. the linker is generating (eg. a DLL or ELF program). This import
  1859. library (which should be called <code>*.dll.a</code> or <code>*.a</code> for DLLs)
  1860. may be used to link clients against the generated executable; this
  1861. behaviour makes it possible to skip a separate import library creation
  1862. step (eg. <code>dlltool</code> for DLLs). This option is only available for
  1863. the i386 PE and ELF targetted ports of the linker.
  1864. </p>
  1865. <a name="index-_002dpie"></a>
  1866. <a name="index-_002d_002dpic_002dexecutable"></a>
  1867. </dd>
  1868. <dt><code>-pie</code></dt>
  1869. <dt><code>--pic-executable</code></dt>
  1870. <dd><a name="index-position-independent-executables"></a>
  1871. <p>Create a position independent executable. This is currently only supported on
  1872. ELF platforms. Position independent executables are similar to shared
  1873. libraries in that they are relocated by the dynamic linker to the virtual
  1874. address the OS chooses for them (which can vary between invocations). Like
  1875. normal dynamically linked executables they can be executed and symbols
  1876. defined in the executable cannot be overridden by shared libraries.
  1877. </p>
  1878. <a name="index-_002dqmagic"></a>
  1879. </dd>
  1880. <dt><code>-qmagic</code></dt>
  1881. <dd><p>This option is ignored for Linux compatibility.
  1882. </p>
  1883. <a name="index-_002dQy"></a>
  1884. </dd>
  1885. <dt><code>-Qy</code></dt>
  1886. <dd><p>This option is ignored for SVR4 compatibility.
  1887. </p>
  1888. <a name="index-_002d_002drelax"></a>
  1889. <a name="index-synthesizing-linker"></a>
  1890. <a name="index-relaxing-addressing-modes"></a>
  1891. <a name="index-_002d_002dno_002drelax"></a>
  1892. </dd>
  1893. <dt><code>--relax</code></dt>
  1894. <dt><code>--no-relax</code></dt>
  1895. <dd><p>An option with machine dependent effects.
  1896. This option is only supported on a few targets.
  1897. See <a href="H8_002f300.html#H8_002f300"><code>ld</code> and the H8/300</a>.
  1898. See <a href="Xtensa.html#Xtensa"><code>ld</code> and Xtensa Processors</a>.
  1899. See <a href="M68HC11_002f68HC12.html#M68HC11_002f68HC12"><code>ld</code> and the 68HC11 and 68HC12</a>.
  1900. See <a href="Nios-II.html#Nios-II"><code>ld</code> and the Altera Nios II</a>.
  1901. See <a href="PowerPC-ELF32.html#PowerPC-ELF32"><code>ld</code> and PowerPC 32-bit ELF Support</a>.
  1902. </p>
  1903. <p>On some platforms the &lsquo;<samp>--relax</samp>&rsquo; option performs target-specific,
  1904. global optimizations that become possible when the linker resolves
  1905. addressing in the program, such as relaxing address modes,
  1906. synthesizing new instructions, selecting shorter version of current
  1907. instructions, and combining constant values.
  1908. </p>
  1909. <p>On some platforms these link time global optimizations may make symbolic
  1910. debugging of the resulting executable impossible.
  1911. This is known to be the case for the Matsushita MN10200 and MN10300
  1912. family of processors.
  1913. </p>
  1914. <p>On platforms where this is not supported, &lsquo;<samp>--relax</samp>&rsquo; is accepted,
  1915. but ignored.
  1916. </p>
  1917. <p>On platforms where &lsquo;<samp>--relax</samp>&rsquo; is accepted the option
  1918. &lsquo;<samp>--no-relax</samp>&rsquo; can be used to disable the feature.
  1919. </p>
  1920. <a name="index-retaining-specified-symbols"></a>
  1921. <a name="index-stripping-all-but-some-symbols"></a>
  1922. <a name="index-symbols_002c-retaining-selectively"></a>
  1923. <a name="index-_002d_002dretain_002dsymbols_002dfile_003dfilename"></a>
  1924. </dd>
  1925. <dt><code>--retain-symbols-file=<var>filename</var></code></dt>
  1926. <dd><p>Retain <em>only</em> the symbols listed in the file <var>filename</var>,
  1927. discarding all others. <var>filename</var> is simply a flat file, with one
  1928. symbol name per line. This option is especially useful in environments
  1929. (such as VxWorks)
  1930. where a large global symbol table is accumulated gradually, to conserve
  1931. run-time memory.
  1932. </p>
  1933. <p>&lsquo;<samp>--retain-symbols-file</samp>&rsquo; does <em>not</em> discard undefined symbols,
  1934. or symbols needed for relocations.
  1935. </p>
  1936. <p>You may only specify &lsquo;<samp>--retain-symbols-file</samp>&rsquo; once in the command
  1937. line. It overrides &lsquo;<samp>-s</samp>&rsquo; and &lsquo;<samp>-S</samp>&rsquo;.
  1938. </p>
  1939. </dd>
  1940. <dt><code>-rpath=<var>dir</var></code></dt>
  1941. <dd><a name="index-runtime-library-search-path"></a>
  1942. <a name="index-_002drpath_003ddir"></a>
  1943. <p>Add a directory to the runtime library search path. This is used when
  1944. linking an ELF executable with shared objects. All <samp>-rpath</samp>
  1945. arguments are concatenated and passed to the runtime linker, which uses
  1946. them to locate shared objects at runtime.
  1947. </p>
  1948. <p>The <samp>-rpath</samp> option is also used when locating shared objects which
  1949. are needed by shared objects explicitly included in the link; see the
  1950. description of the <samp>-rpath-link</samp> option. Searching <samp>-rpath</samp>
  1951. in this way is only supported by native linkers and cross linkers which
  1952. have been configured with the <samp>--with-sysroot</samp> option.
  1953. </p>
  1954. <p>If <samp>-rpath</samp> is not used when linking an ELF executable, the
  1955. contents of the environment variable <code>LD_RUN_PATH</code> will be used if it
  1956. is defined.
  1957. </p>
  1958. <p>The <samp>-rpath</samp> option may also be used on SunOS. By default, on
  1959. SunOS, the linker will form a runtime search path out of all the
  1960. <samp>-L</samp> options it is given. If a <samp>-rpath</samp> option is used, the
  1961. runtime search path will be formed exclusively using the <samp>-rpath</samp>
  1962. options, ignoring the <samp>-L</samp> options. This can be useful when using
  1963. gcc, which adds many <samp>-L</samp> options which may be on NFS mounted
  1964. file systems.
  1965. </p>
  1966. <p>For compatibility with other ELF linkers, if the <samp>-R</samp> option is
  1967. followed by a directory name, rather than a file name, it is treated as
  1968. the <samp>-rpath</samp> option.
  1969. </p>
  1970. <a name="index-link_002dtime-runtime-library-search-path"></a>
  1971. <a name="index-_002drpath_002dlink_003ddir"></a>
  1972. </dd>
  1973. <dt><code>-rpath-link=<var>dir</var></code></dt>
  1974. <dd><p>When using ELF or SunOS, one shared library may require another. This
  1975. happens when an <code>ld -shared</code> link includes a shared library as one
  1976. of the input files.
  1977. </p>
  1978. <p>When the linker encounters such a dependency when doing a non-shared,
  1979. non-relocatable link, it will automatically try to locate the required
  1980. shared library and include it in the link, if it is not included
  1981. explicitly. In such a case, the <samp>-rpath-link</samp> option
  1982. specifies the first set of directories to search. The
  1983. <samp>-rpath-link</samp> option may specify a sequence of directory names
  1984. either by specifying a list of names separated by colons, or by
  1985. appearing multiple times.
  1986. </p>
  1987. <p>The tokens <var>$ORIGIN</var> and <var>$LIB</var> can appear in these search
  1988. directories. They will be replaced by the full path to the directory
  1989. containing the program or shared object in the case of <var>$ORIGIN</var>
  1990. and either &lsquo;<samp>lib</samp>&rsquo; - for 32-bit binaries - or &lsquo;<samp>lib64</samp>&rsquo; - for
  1991. 64-bit binaries - in the case of <var>$LIB</var>.
  1992. </p>
  1993. <p>The alternative form of these tokens - <var>${ORIGIN}</var> and
  1994. <var>${LIB}</var> can also be used. The token <var>$PLATFORM</var> is not
  1995. supported.
  1996. </p>
  1997. <p>This option should be used with caution as it overrides the search path
  1998. that may have been hard compiled into a shared library. In such a case it
  1999. is possible to use unintentionally a different search path than the
  2000. runtime linker would do.
  2001. </p>
  2002. <p>The linker uses the following search paths to locate required shared
  2003. libraries:
  2004. </p>
  2005. <ol>
  2006. <li> Any directories specified by <samp>-rpath-link</samp> options.
  2007. </li><li> Any directories specified by <samp>-rpath</samp> options. The difference
  2008. between <samp>-rpath</samp> and <samp>-rpath-link</samp> is that directories
  2009. specified by <samp>-rpath</samp> options are included in the executable and
  2010. used at runtime, whereas the <samp>-rpath-link</samp> option is only effective
  2011. at link time. Searching <samp>-rpath</samp> in this way is only supported
  2012. by native linkers and cross linkers which have been configured with
  2013. the <samp>--with-sysroot</samp> option.
  2014. </li><li> On an ELF system, for native linkers, if the <samp>-rpath</samp> and
  2015. <samp>-rpath-link</samp> options were not used, search the contents of the
  2016. environment variable <code>LD_RUN_PATH</code>.
  2017. </li><li> On SunOS, if the <samp>-rpath</samp> option was not used, search any
  2018. directories specified using <samp>-L</samp> options.
  2019. </li><li> For a native linker, search the contents of the environment
  2020. variable <code>LD_LIBRARY_PATH</code>.
  2021. </li><li> For a native ELF linker, the directories in <code>DT_RUNPATH</code> or
  2022. <code>DT_RPATH</code> of a shared library are searched for shared
  2023. libraries needed by it. The <code>DT_RPATH</code> entries are ignored if
  2024. <code>DT_RUNPATH</code> entries exist.
  2025. </li><li> The default directories, normally <samp>/lib</samp> and <samp>/usr/lib</samp>.
  2026. </li><li> For a linker for a Linux system, if the file <samp>/etc/ld.so.conf</samp>
  2027. exists, the list of directories found in that file. Note: the path
  2028. to this file is prefixed with the <code>sysroot</code> value, if that is
  2029. defined, and then any <code>prefix</code> string if the linker was
  2030. configured with the <code>--prefix=&lt;path&gt;</code> option.
  2031. </li><li> For a native linker on a FreeBSD system, any directories specified by
  2032. the <code>_PATH_ELF_HINTS</code> macro defined in the <samp>elf-hints.h</samp>
  2033. header file.
  2034. </li><li> Any directories specifed by a <code>SEARCH_DIR</code> command in the
  2035. linker script being used.
  2036. </li></ol>
  2037. <p>If the required shared library is not found, the linker will issue a
  2038. warning and continue with the link.
  2039. </p>
  2040. <a name="index-_002dshared"></a>
  2041. <a name="index-_002dBshareable"></a>
  2042. </dd>
  2043. <dt><code>-shared</code></dt>
  2044. <dt><code>-Bshareable</code></dt>
  2045. <dd><a name="index-shared-libraries"></a>
  2046. <p>Create a shared library. This is currently only supported on ELF, XCOFF
  2047. and SunOS platforms. On SunOS, the linker will automatically create a
  2048. shared library if the <samp>-e</samp> option is not used and there are
  2049. undefined symbols in the link.
  2050. </p>
  2051. <a name="index-_002d_002dsort_002dcommon"></a>
  2052. </dd>
  2053. <dt><code>--sort-common</code></dt>
  2054. <dt><code>--sort-common=ascending</code></dt>
  2055. <dt><code>--sort-common=descending</code></dt>
  2056. <dd><p>This option tells <code>ld</code> to sort the common symbols by alignment in
  2057. ascending or descending order when it places them in the appropriate output
  2058. sections. The symbol alignments considered are sixteen-byte or larger,
  2059. eight-byte, four-byte, two-byte, and one-byte. This is to prevent gaps
  2060. between symbols due to alignment constraints. If no sorting order is
  2061. specified, then descending order is assumed.
  2062. </p>
  2063. <a name="index-_002d_002dsort_002dsection_003dname"></a>
  2064. </dd>
  2065. <dt><code>--sort-section=name</code></dt>
  2066. <dd><p>This option will apply <code>SORT_BY_NAME</code> to all wildcard section
  2067. patterns in the linker script.
  2068. </p>
  2069. <a name="index-_002d_002dsort_002dsection_003dalignment"></a>
  2070. </dd>
  2071. <dt><code>--sort-section=alignment</code></dt>
  2072. <dd><p>This option will apply <code>SORT_BY_ALIGNMENT</code> to all wildcard section
  2073. patterns in the linker script.
  2074. </p>
  2075. <a name="index-_002d_002dspare_002ddynamic_002dtags"></a>
  2076. </dd>
  2077. <dt><code>--spare-dynamic-tags=<var>count</var></code></dt>
  2078. <dd><p>This option specifies the number of empty slots to leave in the
  2079. .dynamic section of ELF shared objects. Empty slots may be needed by
  2080. post processing tools, such as the prelinker. The default is 5.
  2081. </p>
  2082. <a name="index-_002d_002dsplit_002dby_002dfile"></a>
  2083. </dd>
  2084. <dt><code>--split-by-file[=<var>size</var>]</code></dt>
  2085. <dd><p>Similar to <samp>--split-by-reloc</samp> but creates a new output section for
  2086. each input file when <var>size</var> is reached. <var>size</var> defaults to a
  2087. size of 1 if not given.
  2088. </p>
  2089. <a name="index-_002d_002dsplit_002dby_002dreloc"></a>
  2090. </dd>
  2091. <dt><code>--split-by-reloc[=<var>count</var>]</code></dt>
  2092. <dd><p>Tries to creates extra sections in the output file so that no single
  2093. output section in the file contains more than <var>count</var> relocations.
  2094. This is useful when generating huge relocatable files for downloading into
  2095. certain real time kernels with the COFF object file format; since COFF
  2096. cannot represent more than 65535 relocations in a single section. Note
  2097. that this will fail to work with object file formats which do not
  2098. support arbitrary sections. The linker will not split up individual
  2099. input sections for redistribution, so if a single input section contains
  2100. more than <var>count</var> relocations one output section will contain that
  2101. many relocations. <var>count</var> defaults to a value of 32768.
  2102. </p>
  2103. <a name="index-_002d_002dstats"></a>
  2104. </dd>
  2105. <dt><code>--stats</code></dt>
  2106. <dd><p>Compute and display statistics about the operation of the linker, such
  2107. as execution time and memory usage.
  2108. </p>
  2109. <a name="index-_002d_002dsysroot_003ddirectory"></a>
  2110. </dd>
  2111. <dt><code>--sysroot=<var>directory</var></code></dt>
  2112. <dd><p>Use <var>directory</var> as the location of the sysroot, overriding the
  2113. configure-time default. This option is only supported by linkers
  2114. that were configured using <samp>--with-sysroot</samp>.
  2115. </p>
  2116. <a name="index-_002d_002dtask_002dlink"></a>
  2117. </dd>
  2118. <dt><code>--task-link</code></dt>
  2119. <dd><p>This is used by COFF/PE based targets to create a task-linked object
  2120. file where all of the global symbols have been converted to statics.
  2121. </p>
  2122. <a name="index-_002d_002dtraditional_002dformat"></a>
  2123. <a name="index-traditional-format"></a>
  2124. </dd>
  2125. <dt><code>--traditional-format</code></dt>
  2126. <dd><p>For some targets, the output of <code>ld</code> is different in some ways from
  2127. the output of some existing linker. This switch requests <code>ld</code> to
  2128. use the traditional format instead.
  2129. </p>
  2130. <a name="index-dbx"></a>
  2131. <p>For example, on SunOS, <code>ld</code> combines duplicate entries in the
  2132. symbol string table. This can reduce the size of an output file with
  2133. full debugging information by over 30 percent. Unfortunately, the SunOS
  2134. <code>dbx</code> program can not read the resulting program (<code>gdb</code> has no
  2135. trouble). The &lsquo;<samp>--traditional-format</samp>&rsquo; switch tells <code>ld</code> to not
  2136. combine duplicate entries.
  2137. </p>
  2138. <a name="index-_002d_002dsection_002dstart_003dsectionname_003dorg"></a>
  2139. </dd>
  2140. <dt><code>--section-start=<var>sectionname</var>=<var>org</var></code></dt>
  2141. <dd><p>Locate a section in the output file at the absolute
  2142. address given by <var>org</var>. You may use this option as many
  2143. times as necessary to locate multiple sections in the command
  2144. line.
  2145. <var>org</var> must be a single hexadecimal integer;
  2146. for compatibility with other linkers, you may omit the leading
  2147. &lsquo;<samp>0x</samp>&rsquo; usually associated with hexadecimal values. <em>Note:</em> there
  2148. should be no white space between <var>sectionname</var>, the equals
  2149. sign (&ldquo;<tt class="key">=</tt>&rdquo;), and <var>org</var>.
  2150. </p>
  2151. <a name="index-_002dTbss_003dorg"></a>
  2152. <a name="index-_002dTdata_003dorg"></a>
  2153. <a name="index-_002dTtext_003dorg"></a>
  2154. <a name="index-segment-origins_002c-cmd-line"></a>
  2155. </dd>
  2156. <dt><code>-Tbss=<var>org</var></code></dt>
  2157. <dt><code>-Tdata=<var>org</var></code></dt>
  2158. <dt><code>-Ttext=<var>org</var></code></dt>
  2159. <dd><p>Same as <samp>--section-start</samp>, with <code>.bss</code>, <code>.data</code> or
  2160. <code>.text</code> as the <var>sectionname</var>.
  2161. </p>
  2162. <a name="index-_002dTtext_002dsegment_003dorg"></a>
  2163. </dd>
  2164. <dt><code>-Ttext-segment=<var>org</var></code></dt>
  2165. <dd><a name="index-text-segment-origin_002c-cmd-line"></a>
  2166. <p>When creating an ELF executable, it will set the address of the first
  2167. byte of the text segment.
  2168. </p>
  2169. <a name="index-_002dTrodata_002dsegment_003dorg"></a>
  2170. </dd>
  2171. <dt><code>-Trodata-segment=<var>org</var></code></dt>
  2172. <dd><a name="index-rodata-segment-origin_002c-cmd-line"></a>
  2173. <p>When creating an ELF executable or shared object for a target where
  2174. the read-only data is in its own segment separate from the executable
  2175. text, it will set the address of the first byte of the read-only data segment.
  2176. </p>
  2177. <a name="index-_002dTldata_002dsegment_003dorg"></a>
  2178. </dd>
  2179. <dt><code>-Tldata-segment=<var>org</var></code></dt>
  2180. <dd><a name="index-ldata-segment-origin_002c-cmd-line"></a>
  2181. <p>When creating an ELF executable or shared object for x86-64 medium memory
  2182. model, it will set the address of the first byte of the ldata segment.
  2183. </p>
  2184. <a name="index-_002d_002dunresolved_002dsymbols"></a>
  2185. </dd>
  2186. <dt><code>--unresolved-symbols=<var>method</var></code></dt>
  2187. <dd><p>Determine how to handle unresolved symbols. There are four possible
  2188. values for &lsquo;<samp>method</samp>&rsquo;:
  2189. </p>
  2190. <dl compact="compact">
  2191. <dt>&lsquo;<samp>ignore-all</samp>&rsquo;</dt>
  2192. <dd><p>Do not report any unresolved symbols.
  2193. </p>
  2194. </dd>
  2195. <dt>&lsquo;<samp>report-all</samp>&rsquo;</dt>
  2196. <dd><p>Report all unresolved symbols. This is the default.
  2197. </p>
  2198. </dd>
  2199. <dt>&lsquo;<samp>ignore-in-object-files</samp>&rsquo;</dt>
  2200. <dd><p>Report unresolved symbols that are contained in shared libraries, but
  2201. ignore them if they come from regular object files.
  2202. </p>
  2203. </dd>
  2204. <dt>&lsquo;<samp>ignore-in-shared-libs</samp>&rsquo;</dt>
  2205. <dd><p>Report unresolved symbols that come from regular object files, but
  2206. ignore them if they come from shared libraries. This can be useful
  2207. when creating a dynamic binary and it is known that all the shared
  2208. libraries that it should be referencing are included on the linker&rsquo;s
  2209. command line.
  2210. </p></dd>
  2211. </dl>
  2212. <p>The behaviour for shared libraries on their own can also be controlled
  2213. by the <samp>--[no-]allow-shlib-undefined</samp> option.
  2214. </p>
  2215. <p>Normally the linker will generate an error message for each reported
  2216. unresolved symbol but the option <samp>--warn-unresolved-symbols</samp>
  2217. can change this to a warning.
  2218. </p>
  2219. <a name="index-_002d_002dverbose_005b_003dNUMBER_005d"></a>
  2220. <a name="index-verbose_005b_003dNUMBER_005d"></a>
  2221. </dd>
  2222. <dt><code>--dll-verbose</code></dt>
  2223. <dt><code>--verbose[=<var>NUMBER</var>]</code></dt>
  2224. <dd><p>Display the version number for <code>ld</code> and list the linker emulations
  2225. supported. Display which input files can and cannot be opened. Display
  2226. the linker script being used by the linker. If the optional <var>NUMBER</var>
  2227. argument &gt; 1, plugin symbol status will also be displayed.
  2228. </p>
  2229. <a name="index-_002d_002dversion_002dscript_003dversion_002dscriptfile"></a>
  2230. <a name="index-version-script_002c-symbol-versions"></a>
  2231. </dd>
  2232. <dt><code>--version-script=<var>version-scriptfile</var></code></dt>
  2233. <dd><p>Specify the name of a version script to the linker. This is typically
  2234. used when creating shared libraries to specify additional information
  2235. about the version hierarchy for the library being created. This option
  2236. is only fully supported on ELF platforms which support shared libraries;
  2237. see <a href="VERSION.html#VERSION">VERSION</a>. It is partially supported on PE platforms, which can
  2238. use version scripts to filter symbol visibility in auto-export mode: any
  2239. symbols marked &lsquo;<samp>local</samp>&rsquo; in the version script will not be exported.
  2240. See <a href="WIN32.html#WIN32">WIN32</a>.
  2241. </p>
  2242. <a name="index-_002d_002dwarn_002dcommon"></a>
  2243. <a name="index-warnings_002c-on-combining-symbols"></a>
  2244. <a name="index-combining-symbols_002c-warnings-on"></a>
  2245. </dd>
  2246. <dt><code>--warn-common</code></dt>
  2247. <dd><p>Warn when a common symbol is combined with another common symbol or with
  2248. a symbol definition. Unix linkers allow this somewhat sloppy practice,
  2249. but linkers on some other operating systems do not. This option allows
  2250. you to find potential problems from combining global symbols.
  2251. Unfortunately, some C libraries use this practice, so you may get some
  2252. warnings about symbols in the libraries as well as in your programs.
  2253. </p>
  2254. <p>There are three kinds of global symbols, illustrated here by C examples:
  2255. </p>
  2256. <dl compact="compact">
  2257. <dt>&lsquo;<samp>int i = 1;</samp>&rsquo;</dt>
  2258. <dd><p>A definition, which goes in the initialized data section of the output
  2259. file.
  2260. </p>
  2261. </dd>
  2262. <dt>&lsquo;<samp>extern int i;</samp>&rsquo;</dt>
  2263. <dd><p>An undefined reference, which does not allocate space.
  2264. There must be either a definition or a common symbol for the
  2265. variable somewhere.
  2266. </p>
  2267. </dd>
  2268. <dt>&lsquo;<samp>int i;</samp>&rsquo;</dt>
  2269. <dd><p>A common symbol. If there are only (one or more) common symbols for a
  2270. variable, it goes in the uninitialized data area of the output file.
  2271. The linker merges multiple common symbols for the same variable into a
  2272. single symbol. If they are of different sizes, it picks the largest
  2273. size. The linker turns a common symbol into a declaration, if there is
  2274. a definition of the same variable.
  2275. </p></dd>
  2276. </dl>
  2277. <p>The &lsquo;<samp>--warn-common</samp>&rsquo; option can produce five kinds of warnings.
  2278. Each warning consists of a pair of lines: the first describes the symbol
  2279. just encountered, and the second describes the previous symbol
  2280. encountered with the same name. One or both of the two symbols will be
  2281. a common symbol.
  2282. </p>
  2283. <ol>
  2284. <li> Turning a common symbol into a reference, because there is already a
  2285. definition for the symbol.
  2286. <div class="smallexample">
  2287. <pre class="smallexample"><var>file</var>(<var>section</var>): warning: common of `<var>symbol</var>'
  2288. overridden by definition
  2289. <var>file</var>(<var>section</var>): warning: defined here
  2290. </pre></div>
  2291. </li><li> Turning a common symbol into a reference, because a later definition for
  2292. the symbol is encountered. This is the same as the previous case,
  2293. except that the symbols are encountered in a different order.
  2294. <div class="smallexample">
  2295. <pre class="smallexample"><var>file</var>(<var>section</var>): warning: definition of `<var>symbol</var>'
  2296. overriding common
  2297. <var>file</var>(<var>section</var>): warning: common is here
  2298. </pre></div>
  2299. </li><li> Merging a common symbol with a previous same-sized common symbol.
  2300. <div class="smallexample">
  2301. <pre class="smallexample"><var>file</var>(<var>section</var>): warning: multiple common
  2302. of `<var>symbol</var>'
  2303. <var>file</var>(<var>section</var>): warning: previous common is here
  2304. </pre></div>
  2305. </li><li> Merging a common symbol with a previous larger common symbol.
  2306. <div class="smallexample">
  2307. <pre class="smallexample"><var>file</var>(<var>section</var>): warning: common of `<var>symbol</var>'
  2308. overridden by larger common
  2309. <var>file</var>(<var>section</var>): warning: larger common is here
  2310. </pre></div>
  2311. </li><li> Merging a common symbol with a previous smaller common symbol. This is
  2312. the same as the previous case, except that the symbols are
  2313. encountered in a different order.
  2314. <div class="smallexample">
  2315. <pre class="smallexample"><var>file</var>(<var>section</var>): warning: common of `<var>symbol</var>'
  2316. overriding smaller common
  2317. <var>file</var>(<var>section</var>): warning: smaller common is here
  2318. </pre></div>
  2319. </li></ol>
  2320. <a name="index-_002d_002dwarn_002dconstructors"></a>
  2321. </dd>
  2322. <dt><code>--warn-constructors</code></dt>
  2323. <dd><p>Warn if any global constructors are used. This is only useful for a few
  2324. object file formats. For formats like COFF or ELF, the linker can not
  2325. detect the use of global constructors.
  2326. </p>
  2327. <a name="index-_002d_002dwarn_002dmultiple_002dgp"></a>
  2328. </dd>
  2329. <dt><code>--warn-multiple-gp</code></dt>
  2330. <dd><p>Warn if multiple global pointer values are required in the output file.
  2331. This is only meaningful for certain processors, such as the Alpha.
  2332. Specifically, some processors put large-valued constants in a special
  2333. section. A special register (the global pointer) points into the middle
  2334. of this section, so that constants can be loaded efficiently via a
  2335. base-register relative addressing mode. Since the offset in
  2336. base-register relative mode is fixed and relatively small (e.g., 16
  2337. bits), this limits the maximum size of the constant pool. Thus, in
  2338. large programs, it is often necessary to use multiple global pointer
  2339. values in order to be able to address all possible constants. This
  2340. option causes a warning to be issued whenever this case occurs.
  2341. </p>
  2342. <a name="index-_002d_002dwarn_002donce"></a>
  2343. <a name="index-warnings_002c-on-undefined-symbols"></a>
  2344. <a name="index-undefined-symbols_002c-warnings-on"></a>
  2345. </dd>
  2346. <dt><code>--warn-once</code></dt>
  2347. <dd><p>Only warn once for each undefined symbol, rather than once per module
  2348. which refers to it.
  2349. </p>
  2350. <a name="index-_002d_002dwarn_002dsection_002dalign"></a>
  2351. <a name="index-warnings_002c-on-section-alignment"></a>
  2352. <a name="index-section-alignment_002c-warnings-on"></a>
  2353. </dd>
  2354. <dt><code>--warn-section-align</code></dt>
  2355. <dd><p>Warn if the address of an output section is changed because of
  2356. alignment. Typically, the alignment will be set by an input section.
  2357. The address will only be changed if it not explicitly specified; that
  2358. is, if the <code>SECTIONS</code> command does not specify a start address for
  2359. the section (see <a href="SECTIONS.html#SECTIONS">SECTIONS</a>).
  2360. </p>
  2361. <a name="index-_002d_002dwarn_002dtextrel"></a>
  2362. </dd>
  2363. <dt><code>--warn-textrel</code></dt>
  2364. <dd><p>Warn if the linker adds DT_TEXTREL to a position-independent executable
  2365. or shared object.
  2366. </p>
  2367. <a name="index-_002d_002dwarn_002dalternate_002dem"></a>
  2368. </dd>
  2369. <dt><code>--warn-alternate-em</code></dt>
  2370. <dd><p>Warn if an object has alternate ELF machine code.
  2371. </p>
  2372. <a name="index-_002d_002dwarn_002dunresolved_002dsymbols"></a>
  2373. </dd>
  2374. <dt><code>--warn-unresolved-symbols</code></dt>
  2375. <dd><p>If the linker is going to report an unresolved symbol (see the option
  2376. <samp>--unresolved-symbols</samp>) it will normally generate an error.
  2377. This option makes it generate a warning instead.
  2378. </p>
  2379. <a name="index-_002d_002derror_002dunresolved_002dsymbols"></a>
  2380. </dd>
  2381. <dt><code>--error-unresolved-symbols</code></dt>
  2382. <dd><p>This restores the linker&rsquo;s default behaviour of generating errors when
  2383. it is reporting unresolved symbols.
  2384. </p>
  2385. <a name="index-_002d_002dwhole_002darchive"></a>
  2386. <a name="index-including-an-entire-archive"></a>
  2387. </dd>
  2388. <dt><code>--whole-archive</code></dt>
  2389. <dd><p>For each archive mentioned on the command line after the
  2390. <samp>--whole-archive</samp> option, include every object file in the archive
  2391. in the link, rather than searching the archive for the required object
  2392. files. This is normally used to turn an archive file into a shared
  2393. library, forcing every object to be included in the resulting shared
  2394. library. This option may be used more than once.
  2395. </p>
  2396. <p>Two notes when using this option from gcc: First, gcc doesn&rsquo;t know
  2397. about this option, so you have to use <samp>-Wl,-whole-archive</samp>.
  2398. Second, don&rsquo;t forget to use <samp>-Wl,-no-whole-archive</samp> after your
  2399. list of archives, because gcc will add its own list of archives to
  2400. your link and you may not want this flag to affect those as well.
  2401. </p>
  2402. <a name="index-_002d_002dwrap_003dsymbol"></a>
  2403. </dd>
  2404. <dt><code>--wrap=<var>symbol</var></code></dt>
  2405. <dd><p>Use a wrapper function for <var>symbol</var>. Any undefined reference to
  2406. <var>symbol</var> will be resolved to <code>__wrap_<var>symbol</var></code>. Any
  2407. undefined reference to <code>__real_<var>symbol</var></code> will be resolved to
  2408. <var>symbol</var>.
  2409. </p>
  2410. <p>This can be used to provide a wrapper for a system function. The
  2411. wrapper function should be called <code>__wrap_<var>symbol</var></code>. If it
  2412. wishes to call the system function, it should call
  2413. <code>__real_<var>symbol</var></code>.
  2414. </p>
  2415. <p>Here is a trivial example:
  2416. </p>
  2417. <div class="smallexample">
  2418. <pre class="smallexample">void *
  2419. __wrap_malloc (size_t c)
  2420. {
  2421. printf (&quot;malloc called with %zu\n&quot;, c);
  2422. return __real_malloc (c);
  2423. }
  2424. </pre></div>
  2425. <p>If you link other code with this file using <samp>--wrap malloc</samp>, then
  2426. all calls to <code>malloc</code> will call the function <code>__wrap_malloc</code>
  2427. instead. The call to <code>__real_malloc</code> in <code>__wrap_malloc</code> will
  2428. call the real <code>malloc</code> function.
  2429. </p>
  2430. <p>You may wish to provide a <code>__real_malloc</code> function as well, so that
  2431. links without the <samp>--wrap</samp> option will succeed. If you do this,
  2432. you should not put the definition of <code>__real_malloc</code> in the same
  2433. file as <code>__wrap_malloc</code>; if you do, the assembler may resolve the
  2434. call before the linker has a chance to wrap it to <code>malloc</code>.
  2435. </p>
  2436. <p>Only undefined references are replaced by the linker. So, translation unit
  2437. internal references to <var>symbol</var> are not resolved to
  2438. <code>__wrap_<var>symbol</var></code>. In the next example, the call to <code>f</code> in
  2439. <code>g</code> is not resolved to <code>__wrap_f</code>.
  2440. </p>
  2441. <div class="smallexample">
  2442. <pre class="smallexample">int
  2443. f (void)
  2444. {
  2445. return 123;
  2446. }
  2447. int
  2448. g (void)
  2449. {
  2450. return f();
  2451. }
  2452. </pre></div>
  2453. <a name="index-_002d_002deh_002dframe_002dhdr"></a>
  2454. <a name="index-_002d_002dno_002deh_002dframe_002dhdr"></a>
  2455. </dd>
  2456. <dt><code>--eh-frame-hdr</code></dt>
  2457. <dt><code>--no-eh-frame-hdr</code></dt>
  2458. <dd><p>Request (<samp>--eh-frame-hdr</samp>) or suppress
  2459. (<samp>--no-eh-frame-hdr</samp>) the creation of <code>.eh_frame_hdr</code>
  2460. section and ELF <code>PT_GNU_EH_FRAME</code> segment header.
  2461. </p>
  2462. <a name="index-_002d_002dld_002dgenerated_002dunwind_002dinfo"></a>
  2463. </dd>
  2464. <dt><code>--no-ld-generated-unwind-info</code></dt>
  2465. <dd><p>Request creation of <code>.eh_frame</code> unwind info for linker
  2466. generated code sections like PLT. This option is on by default
  2467. if linker generated unwind info is supported.
  2468. </p>
  2469. <a name="index-_002d_002denable_002dnew_002ddtags"></a>
  2470. <a name="index-_002d_002ddisable_002dnew_002ddtags"></a>
  2471. </dd>
  2472. <dt><code>--enable-new-dtags</code></dt>
  2473. <dt><code>--disable-new-dtags</code></dt>
  2474. <dd><p>This linker can create the new dynamic tags in ELF. But the older ELF
  2475. systems may not understand them. If you specify
  2476. <samp>--enable-new-dtags</samp>, the new dynamic tags will be created as needed
  2477. and older dynamic tags will be omitted.
  2478. If you specify <samp>--disable-new-dtags</samp>, no new dynamic tags will be
  2479. created. By default, the new dynamic tags are not created. Note that
  2480. those options are only available for ELF systems.
  2481. </p>
  2482. <a name="index-_002d_002dhash_002dsize_003dnumber"></a>
  2483. </dd>
  2484. <dt><code>--hash-size=<var>number</var></code></dt>
  2485. <dd><p>Set the default size of the linker&rsquo;s hash tables to a prime number
  2486. close to <var>number</var>. Increasing this value can reduce the length of
  2487. time it takes the linker to perform its tasks, at the expense of
  2488. increasing the linker&rsquo;s memory requirements. Similarly reducing this
  2489. value can reduce the memory requirements at the expense of speed.
  2490. </p>
  2491. <a name="index-_002d_002dhash_002dstyle_003dstyle"></a>
  2492. </dd>
  2493. <dt><code>--hash-style=<var>style</var></code></dt>
  2494. <dd><p>Set the type of linker&rsquo;s hash table(s). <var>style</var> can be either
  2495. <code>sysv</code> for classic ELF <code>.hash</code> section, <code>gnu</code> for
  2496. new style GNU <code>.gnu.hash</code> section or <code>both</code> for both
  2497. the classic ELF <code>.hash</code> and new style GNU <code>.gnu.hash</code>
  2498. hash tables. The default depends upon how the linker was configured,
  2499. but for most Linux based systems it will be <code>both</code>.
  2500. </p>
  2501. <a name="index-_002d_002dcompress_002ddebug_002dsections_003dnone"></a>
  2502. <a name="index-_002d_002dcompress_002ddebug_002dsections_003dzlib"></a>
  2503. <a name="index-_002d_002dcompress_002ddebug_002dsections_003dzlib_002dgnu"></a>
  2504. <a name="index-_002d_002dcompress_002ddebug_002dsections_003dzlib_002dgabi"></a>
  2505. </dd>
  2506. <dt><code>--compress-debug-sections=none</code></dt>
  2507. <dt><code>--compress-debug-sections=zlib</code></dt>
  2508. <dt><code>--compress-debug-sections=zlib-gnu</code></dt>
  2509. <dt><code>--compress-debug-sections=zlib-gabi</code></dt>
  2510. <dd><p>On ELF platforms, these options control how DWARF debug sections are
  2511. compressed using zlib.
  2512. </p>
  2513. <p><samp>--compress-debug-sections=none</samp> doesn&rsquo;t compress DWARF debug
  2514. sections. <samp>--compress-debug-sections=zlib-gnu</samp> compresses
  2515. DWARF debug sections and renames them to begin with &lsquo;<samp>.zdebug</samp>&rsquo;
  2516. instead of &lsquo;<samp>.debug</samp>&rsquo;. <samp>--compress-debug-sections=zlib-gabi</samp>
  2517. also compresses DWARF debug sections, but rather than renaming them it
  2518. sets the SHF_COMPRESSED flag in the sections&rsquo; headers.
  2519. </p>
  2520. <p>The <samp>--compress-debug-sections=zlib</samp> option is an alias for
  2521. <samp>--compress-debug-sections=zlib-gabi</samp>.
  2522. </p>
  2523. <p>Note that this option overrides any compression in input debug
  2524. sections, so if a binary is linked with <samp>--compress-debug-sections=none</samp>
  2525. for example, then any compressed debug sections in input files will be
  2526. uncompressed before they are copied into the output binary.
  2527. </p>
  2528. <p>The default compression behaviour varies depending upon the target
  2529. involved and the configure options used to build the toolchain. The
  2530. default can be determined by examining the output from the linker&rsquo;s
  2531. <samp>--help</samp> option.
  2532. </p>
  2533. <a name="index-_002d_002dreduce_002dmemory_002doverheads"></a>
  2534. </dd>
  2535. <dt><code>--reduce-memory-overheads</code></dt>
  2536. <dd><p>This option reduces memory requirements at ld runtime, at the expense of
  2537. linking speed. This was introduced to select the old O(n^2) algorithm
  2538. for link map file generation, rather than the new O(n) algorithm which uses
  2539. about 40% more memory for symbol storage.
  2540. </p>
  2541. <p>Another effect of the switch is to set the default hash table size to
  2542. 1021, which again saves memory at the cost of lengthening the linker&rsquo;s
  2543. run time. This is not done however if the <samp>--hash-size</samp> switch
  2544. has been used.
  2545. </p>
  2546. <p>The <samp>--reduce-memory-overheads</samp> switch may be also be used to
  2547. enable other tradeoffs in future versions of the linker.
  2548. </p>
  2549. <a name="index-_002d_002dbuild_002did"></a>
  2550. <a name="index-_002d_002dbuild_002did_003dstyle"></a>
  2551. </dd>
  2552. <dt><code>--build-id</code></dt>
  2553. <dt><code>--build-id=<var>style</var></code></dt>
  2554. <dd><p>Request the creation of a <code>.note.gnu.build-id</code> ELF note section
  2555. or a <code>.buildid</code> COFF section. The contents of the note are
  2556. unique bits identifying this linked file. <var>style</var> can be
  2557. <code>uuid</code> to use 128 random bits, <code>sha1</code> to use a 160-bit
  2558. <small>SHA1</small> hash on the normative parts of the output contents,
  2559. <code>md5</code> to use a 128-bit <small>MD5</small> hash on the normative parts of
  2560. the output contents, or <code>0x<var>hexstring</var></code> to use a chosen bit
  2561. string specified as an even number of hexadecimal digits (<code>-</code> and
  2562. <code>:</code> characters between digit pairs are ignored). If <var>style</var>
  2563. is omitted, <code>sha1</code> is used.
  2564. </p>
  2565. <p>The <code>md5</code> and <code>sha1</code> styles produces an identifier
  2566. that is always the same in an identical output file, but will be
  2567. unique among all nonidentical output files. It is not intended
  2568. to be compared as a checksum for the file&rsquo;s contents. A linked
  2569. file may be changed later by other tools, but the build ID bit
  2570. string identifying the original linked file does not change.
  2571. </p>
  2572. <p>Passing <code>none</code> for <var>style</var> disables the setting from any
  2573. <code>--build-id</code> options earlier on the command line.
  2574. </p></dd>
  2575. </dl>
  2576. <a name="Options-Specific-to-i386-PE-Targets"></a>
  2577. <h4 class="subsection">2.1.1 Options Specific to i386 PE Targets</h4>
  2578. <p>The i386 PE linker supports the <samp>-shared</samp> option, which causes
  2579. the output to be a dynamically linked library (DLL) instead of a
  2580. normal executable. You should name the output <code>*.dll</code> when you
  2581. use this option. In addition, the linker fully supports the standard
  2582. <code>*.def</code> files, which may be specified on the linker command line
  2583. like an object file (in fact, it should precede archives it exports
  2584. symbols from, to ensure that they get linked in, just like a normal
  2585. object file).
  2586. </p>
  2587. <p>In addition to the options common to all targets, the i386 PE linker
  2588. support additional command-line options that are specific to the i386
  2589. PE target. Options that take values may be separated from their
  2590. values by either a space or an equals sign.
  2591. </p>
  2592. <dl compact="compact">
  2593. <dd>
  2594. <a name="index-_002d_002dadd_002dstdcall_002dalias"></a>
  2595. </dd>
  2596. <dt><code>--add-stdcall-alias</code></dt>
  2597. <dd><p>If given, symbols with a stdcall suffix (@<var>nn</var>) will be exported
  2598. as-is and also with the suffix stripped.
  2599. [This option is specific to the i386 PE targeted port of the linker]
  2600. </p>
  2601. <a name="index-_002d_002dbase_002dfile"></a>
  2602. </dd>
  2603. <dt><code>--base-file <var>file</var></code></dt>
  2604. <dd><p>Use <var>file</var> as the name of a file in which to save the base
  2605. addresses of all the relocations needed for generating DLLs with
  2606. <samp>dlltool</samp>.
  2607. [This is an i386 PE specific option]
  2608. </p>
  2609. <a name="index-_002d_002ddll"></a>
  2610. </dd>
  2611. <dt><code>--dll</code></dt>
  2612. <dd><p>Create a DLL instead of a regular executable. You may also use
  2613. <samp>-shared</samp> or specify a <code>LIBRARY</code> in a given <code>.def</code>
  2614. file.
  2615. [This option is specific to the i386 PE targeted port of the linker]
  2616. </p>
  2617. <a name="index-_002d_002denable_002dlong_002dsection_002dnames"></a>
  2618. <a name="index-_002d_002ddisable_002dlong_002dsection_002dnames"></a>
  2619. </dd>
  2620. <dt><code>--enable-long-section-names</code></dt>
  2621. <dt><code>--disable-long-section-names</code></dt>
  2622. <dd><p>The PE variants of the COFF object format add an extension that permits
  2623. the use of section names longer than eight characters, the normal limit
  2624. for COFF. By default, these names are only allowed in object files, as
  2625. fully-linked executable images do not carry the COFF string table required
  2626. to support the longer names. As a GNU extension, it is possible to
  2627. allow their use in executable images as well, or to (probably pointlessly!)
  2628. disallow it in object files, by using these two options. Executable images
  2629. generated with these long section names are slightly non-standard, carrying
  2630. as they do a string table, and may generate confusing output when examined
  2631. with non-GNU PE-aware tools, such as file viewers and dumpers. However,
  2632. GDB relies on the use of PE long section names to find Dwarf-2 debug
  2633. information sections in an executable image at runtime, and so if neither
  2634. option is specified on the command-line, <code>ld</code> will enable long
  2635. section names, overriding the default and technically correct behaviour,
  2636. when it finds the presence of debug information while linking an executable
  2637. image and not stripping symbols.
  2638. [This option is valid for all PE targeted ports of the linker]
  2639. </p>
  2640. <a name="index-_002d_002denable_002dstdcall_002dfixup"></a>
  2641. <a name="index-_002d_002ddisable_002dstdcall_002dfixup"></a>
  2642. </dd>
  2643. <dt><code>--enable-stdcall-fixup</code></dt>
  2644. <dt><code>--disable-stdcall-fixup</code></dt>
  2645. <dd><p>If the link finds a symbol that it cannot resolve, it will attempt to
  2646. do &ldquo;fuzzy linking&rdquo; by looking for another defined symbol that differs
  2647. only in the format of the symbol name (cdecl vs stdcall) and will
  2648. resolve that symbol by linking to the match. For example, the
  2649. undefined symbol <code>_foo</code> might be linked to the function
  2650. <code>_foo@12</code>, or the undefined symbol <code>_bar@16</code> might be linked
  2651. to the function <code>_bar</code>. When the linker does this, it prints a
  2652. warning, since it normally should have failed to link, but sometimes
  2653. import libraries generated from third-party dlls may need this feature
  2654. to be usable. If you specify <samp>--enable-stdcall-fixup</samp>, this
  2655. feature is fully enabled and warnings are not printed. If you specify
  2656. <samp>--disable-stdcall-fixup</samp>, this feature is disabled and such
  2657. mismatches are considered to be errors.
  2658. [This option is specific to the i386 PE targeted port of the linker]
  2659. </p>
  2660. <a name="index-_002d_002dleading_002dunderscore"></a>
  2661. <a name="index-_002d_002dno_002dleading_002dunderscore"></a>
  2662. </dd>
  2663. <dt><code>--leading-underscore</code></dt>
  2664. <dt><code>--no-leading-underscore</code></dt>
  2665. <dd><p>For most targets default symbol-prefix is an underscore and is defined
  2666. in target&rsquo;s description. By this option it is possible to
  2667. disable/enable the default underscore symbol-prefix.
  2668. </p>
  2669. <a name="index-DLLs_002c-creating"></a>
  2670. <a name="index-_002d_002dexport_002dall_002dsymbols"></a>
  2671. </dd>
  2672. <dt><code>--export-all-symbols</code></dt>
  2673. <dd><p>If given, all global symbols in the objects used to build a DLL will
  2674. be exported by the DLL. Note that this is the default if there
  2675. otherwise wouldn&rsquo;t be any exported symbols. When symbols are
  2676. explicitly exported via DEF files or implicitly exported via function
  2677. attributes, the default is to not export anything else unless this
  2678. option is given. Note that the symbols <code>DllMain@12</code>,
  2679. <code>DllEntryPoint@0</code>, <code>DllMainCRTStartup@12</code>, and
  2680. <code>impure_ptr</code> will not be automatically
  2681. exported. Also, symbols imported from other DLLs will not be
  2682. re-exported, nor will symbols specifying the DLL&rsquo;s internal layout
  2683. such as those beginning with <code>_head_</code> or ending with
  2684. <code>_iname</code>. In addition, no symbols from <code>libgcc</code>,
  2685. <code>libstd++</code>, <code>libmingw32</code>, or <code>crtX.o</code> will be exported.
  2686. Symbols whose names begin with <code>__rtti_</code> or <code>__builtin_</code> will
  2687. not be exported, to help with C++ DLLs. Finally, there is an
  2688. extensive list of cygwin-private symbols that are not exported
  2689. (obviously, this applies on when building DLLs for cygwin targets).
  2690. These cygwin-excludes are: <code>_cygwin_dll_entry@12</code>,
  2691. <code>_cygwin_crt0_common@8</code>, <code>_cygwin_noncygwin_dll_entry@12</code>,
  2692. <code>_fmode</code>, <code>_impure_ptr</code>, <code>cygwin_attach_dll</code>,
  2693. <code>cygwin_premain0</code>, <code>cygwin_premain1</code>, <code>cygwin_premain2</code>,
  2694. <code>cygwin_premain3</code>, and <code>environ</code>.
  2695. [This option is specific to the i386 PE targeted port of the linker]
  2696. </p>
  2697. <a name="index-_002d_002dexclude_002dsymbols"></a>
  2698. </dd>
  2699. <dt><code>--exclude-symbols <var>symbol</var>,<var>symbol</var>,...</code></dt>
  2700. <dd><p>Specifies a list of symbols which should not be automatically
  2701. exported. The symbol names may be delimited by commas or colons.
  2702. [This option is specific to the i386 PE targeted port of the linker]
  2703. </p>
  2704. <a name="index-_002d_002dexclude_002dall_002dsymbols"></a>
  2705. </dd>
  2706. <dt><code>--exclude-all-symbols</code></dt>
  2707. <dd><p>Specifies no symbols should be automatically exported.
  2708. [This option is specific to the i386 PE targeted port of the linker]
  2709. </p>
  2710. <a name="index-_002d_002dfile_002dalignment"></a>
  2711. </dd>
  2712. <dt><code>--file-alignment</code></dt>
  2713. <dd><p>Specify the file alignment. Sections in the file will always begin at
  2714. file offsets which are multiples of this number. This defaults to
  2715. 512.
  2716. [This option is specific to the i386 PE targeted port of the linker]
  2717. </p>
  2718. <a name="index-heap-size"></a>
  2719. <a name="index-_002d_002dheap"></a>
  2720. </dd>
  2721. <dt><code>--heap <var>reserve</var></code></dt>
  2722. <dt><code>--heap <var>reserve</var>,<var>commit</var></code></dt>
  2723. <dd><p>Specify the number of bytes of memory to reserve (and optionally commit)
  2724. to be used as heap for this program. The default is 1MB reserved, 4K
  2725. committed.
  2726. [This option is specific to the i386 PE targeted port of the linker]
  2727. </p>
  2728. <a name="index-image-base"></a>
  2729. <a name="index-_002d_002dimage_002dbase"></a>
  2730. </dd>
  2731. <dt><code>--image-base <var>value</var></code></dt>
  2732. <dd><p>Use <var>value</var> as the base address of your program or dll. This is
  2733. the lowest memory location that will be used when your program or dll
  2734. is loaded. To reduce the need to relocate and improve performance of
  2735. your dlls, each should have a unique base address and not overlap any
  2736. other dlls. The default is 0x400000 for executables, and 0x10000000
  2737. for dlls.
  2738. [This option is specific to the i386 PE targeted port of the linker]
  2739. </p>
  2740. <a name="index-_002d_002dkill_002dat"></a>
  2741. </dd>
  2742. <dt><code>--kill-at</code></dt>
  2743. <dd><p>If given, the stdcall suffixes (@<var>nn</var>) will be stripped from
  2744. symbols before they are exported.
  2745. [This option is specific to the i386 PE targeted port of the linker]
  2746. </p>
  2747. <a name="index-_002d_002dlarge_002daddress_002daware"></a>
  2748. </dd>
  2749. <dt><code>--large-address-aware</code></dt>
  2750. <dd><p>If given, the appropriate bit in the &ldquo;Characteristics&rdquo; field of the COFF
  2751. header is set to indicate that this executable supports virtual addresses
  2752. greater than 2 gigabytes. This should be used in conjunction with the /3GB
  2753. or /USERVA=<var>value</var> megabytes switch in the &ldquo;[operating systems]&rdquo;
  2754. section of the BOOT.INI. Otherwise, this bit has no effect.
  2755. [This option is specific to PE targeted ports of the linker]
  2756. </p>
  2757. <a name="index-_002d_002ddisable_002dlarge_002daddress_002daware"></a>
  2758. </dd>
  2759. <dt><code>--disable-large-address-aware</code></dt>
  2760. <dd><p>Reverts the effect of a previous &lsquo;<samp>--large-address-aware</samp>&rsquo; option.
  2761. This is useful if &lsquo;<samp>--large-address-aware</samp>&rsquo; is always set by the compiler
  2762. driver (e.g. Cygwin gcc) and the executable does not support virtual
  2763. addresses greater than 2 gigabytes.
  2764. [This option is specific to PE targeted ports of the linker]
  2765. </p>
  2766. <a name="index-_002d_002dmajor_002dimage_002dversion"></a>
  2767. </dd>
  2768. <dt><code>--major-image-version <var>value</var></code></dt>
  2769. <dd><p>Sets the major number of the &ldquo;image version&rdquo;. Defaults to 1.
  2770. [This option is specific to the i386 PE targeted port of the linker]
  2771. </p>
  2772. <a name="index-_002d_002dmajor_002dos_002dversion"></a>
  2773. </dd>
  2774. <dt><code>--major-os-version <var>value</var></code></dt>
  2775. <dd><p>Sets the major number of the &ldquo;os version&rdquo;. Defaults to 4.
  2776. [This option is specific to the i386 PE targeted port of the linker]
  2777. </p>
  2778. <a name="index-_002d_002dmajor_002dsubsystem_002dversion"></a>
  2779. </dd>
  2780. <dt><code>--major-subsystem-version <var>value</var></code></dt>
  2781. <dd><p>Sets the major number of the &ldquo;subsystem version&rdquo;. Defaults to 4.
  2782. [This option is specific to the i386 PE targeted port of the linker]
  2783. </p>
  2784. <a name="index-_002d_002dminor_002dimage_002dversion"></a>
  2785. </dd>
  2786. <dt><code>--minor-image-version <var>value</var></code></dt>
  2787. <dd><p>Sets the minor number of the &ldquo;image version&rdquo;. Defaults to 0.
  2788. [This option is specific to the i386 PE targeted port of the linker]
  2789. </p>
  2790. <a name="index-_002d_002dminor_002dos_002dversion"></a>
  2791. </dd>
  2792. <dt><code>--minor-os-version <var>value</var></code></dt>
  2793. <dd><p>Sets the minor number of the &ldquo;os version&rdquo;. Defaults to 0.
  2794. [This option is specific to the i386 PE targeted port of the linker]
  2795. </p>
  2796. <a name="index-_002d_002dminor_002dsubsystem_002dversion"></a>
  2797. </dd>
  2798. <dt><code>--minor-subsystem-version <var>value</var></code></dt>
  2799. <dd><p>Sets the minor number of the &ldquo;subsystem version&rdquo;. Defaults to 0.
  2800. [This option is specific to the i386 PE targeted port of the linker]
  2801. </p>
  2802. <a name="index-DEF-files_002c-creating"></a>
  2803. <a name="index-DLLs_002c-creating-1"></a>
  2804. <a name="index-_002d_002doutput_002ddef"></a>
  2805. </dd>
  2806. <dt><code>--output-def <var>file</var></code></dt>
  2807. <dd><p>The linker will create the file <var>file</var> which will contain a DEF
  2808. file corresponding to the DLL the linker is generating. This DEF file
  2809. (which should be called <code>*.def</code>) may be used to create an import
  2810. library with <code>dlltool</code> or may be used as a reference to
  2811. automatically or implicitly exported symbols.
  2812. [This option is specific to the i386 PE targeted port of the linker]
  2813. </p>
  2814. <a name="index-DLLs_002c-creating-2"></a>
  2815. <a name="index-_002d_002denable_002dauto_002dimage_002dbase"></a>
  2816. </dd>
  2817. <dt><code>--enable-auto-image-base</code></dt>
  2818. <dt><code>--enable-auto-image-base=<var>value</var></code></dt>
  2819. <dd><p>Automatically choose the image base for DLLs, optionally starting with base
  2820. <var>value</var>, unless one is specified using the <code>--image-base</code> argument.
  2821. By using a hash generated from the dllname to create unique image bases
  2822. for each DLL, in-memory collisions and relocations which can delay program
  2823. execution are avoided.
  2824. [This option is specific to the i386 PE targeted port of the linker]
  2825. </p>
  2826. <a name="index-_002d_002ddisable_002dauto_002dimage_002dbase"></a>
  2827. </dd>
  2828. <dt><code>--disable-auto-image-base</code></dt>
  2829. <dd><p>Do not automatically generate a unique image base. If there is no
  2830. user-specified image base (<code>--image-base</code>) then use the platform
  2831. default.
  2832. [This option is specific to the i386 PE targeted port of the linker]
  2833. </p>
  2834. <a name="index-DLLs_002c-linking-to"></a>
  2835. <a name="index-_002d_002ddll_002dsearch_002dprefix"></a>
  2836. </dd>
  2837. <dt><code>--dll-search-prefix <var>string</var></code></dt>
  2838. <dd><p>When linking dynamically to a dll without an import library,
  2839. search for <code>&lt;string&gt;&lt;basename&gt;.dll</code> in preference to
  2840. <code>lib&lt;basename&gt;.dll</code>. This behaviour allows easy distinction
  2841. between DLLs built for the various &quot;subplatforms&quot;: native, cygwin,
  2842. uwin, pw, etc. For instance, cygwin DLLs typically use
  2843. <code>--dll-search-prefix=cyg</code>.
  2844. [This option is specific to the i386 PE targeted port of the linker]
  2845. </p>
  2846. <a name="index-_002d_002denable_002dauto_002dimport"></a>
  2847. </dd>
  2848. <dt><code>--enable-auto-import</code></dt>
  2849. <dd><p>Do sophisticated linking of <code>_symbol</code> to <code>__imp__symbol</code> for
  2850. DATA imports from DLLs, thus making it possible to bypass the dllimport
  2851. mechanism on the user side and to reference unmangled symbol names.
  2852. [This option is specific to the i386 PE targeted port of the linker]
  2853. </p>
  2854. <p>The following remarks pertain to the original implementation of the
  2855. feature and are obsolete nowadays for Cygwin and MinGW targets.
  2856. </p>
  2857. <p>Note: Use of the &rsquo;auto-import&rsquo; extension will cause the text section
  2858. of the image file to be made writable. This does not conform to the
  2859. PE-COFF format specification published by Microsoft.
  2860. </p>
  2861. <p>Note - use of the &rsquo;auto-import&rsquo; extension will also cause read only
  2862. data which would normally be placed into the .rdata section to be
  2863. placed into the .data section instead. This is in order to work
  2864. around a problem with consts that is described here:
  2865. http://www.cygwin.com/ml/cygwin/2004-09/msg01101.html
  2866. </p>
  2867. <p>Using &rsquo;auto-import&rsquo; generally will &rsquo;just work&rsquo; &ndash; but sometimes you may
  2868. see this message:
  2869. </p>
  2870. <p>&quot;variable &rsquo;&lt;var&gt;&rsquo; can&rsquo;t be auto-imported. Please read the
  2871. documentation for ld&rsquo;s <code>--enable-auto-import</code> for details.&quot;
  2872. </p>
  2873. <p>This message occurs when some (sub)expression accesses an address
  2874. ultimately given by the sum of two constants (Win32 import tables only
  2875. allow one). Instances where this may occur include accesses to member
  2876. fields of struct variables imported from a DLL, as well as using a
  2877. constant index into an array variable imported from a DLL. Any
  2878. multiword variable (arrays, structs, long long, etc) may trigger
  2879. this error condition. However, regardless of the exact data type
  2880. of the offending exported variable, ld will always detect it, issue
  2881. the warning, and exit.
  2882. </p>
  2883. <p>There are several ways to address this difficulty, regardless of the
  2884. data type of the exported variable:
  2885. </p>
  2886. <p>One way is to use &ndash;enable-runtime-pseudo-reloc switch. This leaves the task
  2887. of adjusting references in your client code for runtime environment, so
  2888. this method works only when runtime environment supports this feature.
  2889. </p>
  2890. <p>A second solution is to force one of the &rsquo;constants&rsquo; to be a variable &ndash;
  2891. that is, unknown and un-optimizable at compile time. For arrays,
  2892. there are two possibilities: a) make the indexee (the array&rsquo;s address)
  2893. a variable, or b) make the &rsquo;constant&rsquo; index a variable. Thus:
  2894. </p>
  2895. <div class="example">
  2896. <pre class="example">extern type extern_array[];
  2897. extern_array[1] --&gt;
  2898. { volatile type *t=extern_array; t[1] }
  2899. </pre></div>
  2900. <p>or
  2901. </p>
  2902. <div class="example">
  2903. <pre class="example">extern type extern_array[];
  2904. extern_array[1] --&gt;
  2905. { volatile int t=1; extern_array[t] }
  2906. </pre></div>
  2907. <p>For structs (and most other multiword data types) the only option
  2908. is to make the struct itself (or the long long, or the ...) variable:
  2909. </p>
  2910. <div class="example">
  2911. <pre class="example">extern struct s extern_struct;
  2912. extern_struct.field --&gt;
  2913. { volatile struct s *t=&amp;extern_struct; t-&gt;field }
  2914. </pre></div>
  2915. <p>or
  2916. </p>
  2917. <div class="example">
  2918. <pre class="example">extern long long extern_ll;
  2919. extern_ll --&gt;
  2920. { volatile long long * local_ll=&amp;extern_ll; *local_ll }
  2921. </pre></div>
  2922. <p>A third method of dealing with this difficulty is to abandon
  2923. &rsquo;auto-import&rsquo; for the offending symbol and mark it with
  2924. <code>__declspec(dllimport)</code>. However, in practice that
  2925. requires using compile-time #defines to indicate whether you are
  2926. building a DLL, building client code that will link to the DLL, or
  2927. merely building/linking to a static library. In making the choice
  2928. between the various methods of resolving the &rsquo;direct address with
  2929. constant offset&rsquo; problem, you should consider typical real-world usage:
  2930. </p>
  2931. <p>Original:
  2932. </p><div class="example">
  2933. <pre class="example">--foo.h
  2934. extern int arr[];
  2935. --foo.c
  2936. #include &quot;foo.h&quot;
  2937. void main(int argc, char **argv){
  2938. printf(&quot;%d\n&quot;,arr[1]);
  2939. }
  2940. </pre></div>
  2941. <p>Solution 1:
  2942. </p><div class="example">
  2943. <pre class="example">--foo.h
  2944. extern int arr[];
  2945. --foo.c
  2946. #include &quot;foo.h&quot;
  2947. void main(int argc, char **argv){
  2948. /* This workaround is for win32 and cygwin; do not &quot;optimize&quot; */
  2949. volatile int *parr = arr;
  2950. printf(&quot;%d\n&quot;,parr[1]);
  2951. }
  2952. </pre></div>
  2953. <p>Solution 2:
  2954. </p><div class="example">
  2955. <pre class="example">--foo.h
  2956. /* Note: auto-export is assumed (no __declspec(dllexport)) */
  2957. #if (defined(_WIN32) || defined(__CYGWIN__)) &amp;&amp; \
  2958. !(defined(FOO_BUILD_DLL) || defined(FOO_STATIC))
  2959. #define FOO_IMPORT __declspec(dllimport)
  2960. #else
  2961. #define FOO_IMPORT
  2962. #endif
  2963. extern FOO_IMPORT int arr[];
  2964. --foo.c
  2965. #include &quot;foo.h&quot;
  2966. void main(int argc, char **argv){
  2967. printf(&quot;%d\n&quot;,arr[1]);
  2968. }
  2969. </pre></div>
  2970. <p>A fourth way to avoid this problem is to re-code your
  2971. library to use a functional interface rather than a data interface
  2972. for the offending variables (e.g. set_foo() and get_foo() accessor
  2973. functions).
  2974. </p>
  2975. <a name="index-_002d_002ddisable_002dauto_002dimport"></a>
  2976. </dd>
  2977. <dt><code>--disable-auto-import</code></dt>
  2978. <dd><p>Do not attempt to do sophisticated linking of <code>_symbol</code> to
  2979. <code>__imp__symbol</code> for DATA imports from DLLs.
  2980. [This option is specific to the i386 PE targeted port of the linker]
  2981. </p>
  2982. <a name="index-_002d_002denable_002druntime_002dpseudo_002dreloc"></a>
  2983. </dd>
  2984. <dt><code>--enable-runtime-pseudo-reloc</code></dt>
  2985. <dd><p>If your code contains expressions described in &ndash;enable-auto-import section,
  2986. that is, DATA imports from DLL with non-zero offset, this switch will create
  2987. a vector of &rsquo;runtime pseudo relocations&rsquo; which can be used by runtime
  2988. environment to adjust references to such data in your client code.
  2989. [This option is specific to the i386 PE targeted port of the linker]
  2990. </p>
  2991. <a name="index-_002d_002ddisable_002druntime_002dpseudo_002dreloc"></a>
  2992. </dd>
  2993. <dt><code>--disable-runtime-pseudo-reloc</code></dt>
  2994. <dd><p>Do not create pseudo relocations for non-zero offset DATA imports from DLLs.
  2995. [This option is specific to the i386 PE targeted port of the linker]
  2996. </p>
  2997. <a name="index-_002d_002denable_002dextra_002dpe_002ddebug"></a>
  2998. </dd>
  2999. <dt><code>--enable-extra-pe-debug</code></dt>
  3000. <dd><p>Show additional debug info related to auto-import symbol thunking.
  3001. [This option is specific to the i386 PE targeted port of the linker]
  3002. </p>
  3003. <a name="index-_002d_002dsection_002dalignment"></a>
  3004. </dd>
  3005. <dt><code>--section-alignment</code></dt>
  3006. <dd><p>Sets the section alignment. Sections in memory will always begin at
  3007. addresses which are a multiple of this number. Defaults to 0x1000.
  3008. [This option is specific to the i386 PE targeted port of the linker]
  3009. </p>
  3010. <a name="index-stack-size"></a>
  3011. <a name="index-_002d_002dstack"></a>
  3012. </dd>
  3013. <dt><code>--stack <var>reserve</var></code></dt>
  3014. <dt><code>--stack <var>reserve</var>,<var>commit</var></code></dt>
  3015. <dd><p>Specify the number of bytes of memory to reserve (and optionally commit)
  3016. to be used as stack for this program. The default is 2MB reserved, 4K
  3017. committed.
  3018. [This option is specific to the i386 PE targeted port of the linker]
  3019. </p>
  3020. <a name="index-_002d_002dsubsystem"></a>
  3021. </dd>
  3022. <dt><code>--subsystem <var>which</var></code></dt>
  3023. <dt><code>--subsystem <var>which</var>:<var>major</var></code></dt>
  3024. <dt><code>--subsystem <var>which</var>:<var>major</var>.<var>minor</var></code></dt>
  3025. <dd><p>Specifies the subsystem under which your program will execute. The
  3026. legal values for <var>which</var> are <code>native</code>, <code>windows</code>,
  3027. <code>console</code>, <code>posix</code>, and <code>xbox</code>. You may optionally set
  3028. the subsystem version also. Numeric values are also accepted for
  3029. <var>which</var>.
  3030. [This option is specific to the i386 PE targeted port of the linker]
  3031. </p>
  3032. <p>The following options set flags in the <code>DllCharacteristics</code> field
  3033. of the PE file header:
  3034. [These options are specific to PE targeted ports of the linker]
  3035. </p>
  3036. <a name="index-_002d_002dhigh_002dentropy_002dva"></a>
  3037. </dd>
  3038. <dt><code>--high-entropy-va</code></dt>
  3039. <dd><p>Image is compatible with 64-bit address space layout randomization
  3040. (ASLR).
  3041. This option also implies <samp>--dynamicbase</samp> and
  3042. <samp>--enable-reloc-section</samp>.
  3043. </p>
  3044. <a name="index-_002d_002ddynamicbase"></a>
  3045. </dd>
  3046. <dt><code>--dynamicbase</code></dt>
  3047. <dd><p>The image base address may be relocated using address space layout
  3048. randomization (ASLR). This feature was introduced with MS Windows
  3049. Vista for i386 PE targets.
  3050. This option also implies <samp>--enable-reloc-section</samp>.
  3051. </p>
  3052. <a name="index-_002d_002dforceinteg"></a>
  3053. </dd>
  3054. <dt><code>--forceinteg</code></dt>
  3055. <dd><p>Code integrity checks are enforced.
  3056. </p>
  3057. <a name="index-_002d_002dnxcompat"></a>
  3058. </dd>
  3059. <dt><code>--nxcompat</code></dt>
  3060. <dd><p>The image is compatible with the Data Execution Prevention.
  3061. This feature was introduced with MS Windows XP SP2 for i386 PE targets.
  3062. </p>
  3063. <a name="index-_002d_002dno_002disolation"></a>
  3064. </dd>
  3065. <dt><code>--no-isolation</code></dt>
  3066. <dd><p>Although the image understands isolation, do not isolate the image.
  3067. </p>
  3068. <a name="index-_002d_002dno_002dseh"></a>
  3069. </dd>
  3070. <dt><code>--no-seh</code></dt>
  3071. <dd><p>The image does not use SEH. No SE handler may be called from
  3072. this image.
  3073. </p>
  3074. <a name="index-_002d_002dno_002dbind"></a>
  3075. </dd>
  3076. <dt><code>--no-bind</code></dt>
  3077. <dd><p>Do not bind this image.
  3078. </p>
  3079. <a name="index-_002d_002dwdmdriver"></a>
  3080. </dd>
  3081. <dt><code>--wdmdriver</code></dt>
  3082. <dd><p>The driver uses the MS Windows Driver Model.
  3083. </p>
  3084. <a name="index-_002d_002dtsaware"></a>
  3085. </dd>
  3086. <dt><code>--tsaware</code></dt>
  3087. <dd><p>The image is Terminal Server aware.
  3088. </p>
  3089. <a name="index-_002d_002dinsert_002dtimestamp"></a>
  3090. </dd>
  3091. <dt><code>--insert-timestamp</code></dt>
  3092. <dt><code>--no-insert-timestamp</code></dt>
  3093. <dd><p>Insert a real timestamp into the image. This is the default behaviour
  3094. as it matches legacy code and it means that the image will work with
  3095. other, proprietary tools. The problem with this default is that it
  3096. will result in slightly different images being produced each time the
  3097. same sources are linked. The option <samp>--no-insert-timestamp</samp>
  3098. can be used to insert a zero value for the timestamp, this ensuring
  3099. that binaries produced from identical sources will compare
  3100. identically.
  3101. </p>
  3102. <a name="index-_002d_002denable_002dreloc_002dsection"></a>
  3103. </dd>
  3104. <dt><code>--enable-reloc-section</code></dt>
  3105. <dd><p>Create the base relocation table, which is necessary if the image
  3106. is loaded at a different image base than specified in the PE header.
  3107. </p></dd>
  3108. </dl>
  3109. <a name="Options-specific-to-C6X-uClinux-targets"></a>
  3110. <h4 class="subsection">2.1.2 Options specific to C6X uClinux targets</h4>
  3111. <p>The C6X uClinux target uses a binary format called DSBT to support shared
  3112. libraries. Each shared library in the system needs to have a unique index;
  3113. all executables use an index of 0.
  3114. </p>
  3115. <dl compact="compact">
  3116. <dd>
  3117. <a name="index-_002d_002ddsbt_002dsize"></a>
  3118. </dd>
  3119. <dt><code>--dsbt-size <var>size</var></code></dt>
  3120. <dd><p>This option sets the number of entries in the DSBT of the current executable
  3121. or shared library to <var>size</var>. The default is to create a table with 64
  3122. entries.
  3123. </p>
  3124. <a name="index-_002d_002ddsbt_002dindex"></a>
  3125. </dd>
  3126. <dt><code>--dsbt-index <var>index</var></code></dt>
  3127. <dd><p>This option sets the DSBT index of the current executable or shared library
  3128. to <var>index</var>. The default is 0, which is appropriate for generating
  3129. executables. If a shared library is generated with a DSBT index of 0, the
  3130. <code>R_C6000_DSBT_INDEX</code> relocs are copied into the output file.
  3131. </p>
  3132. <a name="index-_002d_002dno_002dmerge_002dexidx_002dentries"></a>
  3133. <p>The &lsquo;<samp>--no-merge-exidx-entries</samp>&rsquo; switch disables the merging of adjacent
  3134. exidx entries in frame unwind info.
  3135. </p>
  3136. </dd>
  3137. </dl>
  3138. <a name="Options-specific-to-C_002dSKY-targets"></a>
  3139. <h4 class="subsection">2.1.3 Options specific to C-SKY targets</h4>
  3140. <dl compact="compact">
  3141. <dd>
  3142. <a name="index-_002d_002dbranch_002dstub-on-C_002dSKY"></a>
  3143. </dd>
  3144. <dt><code>--branch-stub</code></dt>
  3145. <dd><p>This option enables linker branch relaxation by inserting branch stub
  3146. sections when needed to extend the range of branches. This option is
  3147. usually not required since C-SKY supports branch and call instructions that
  3148. can access the full memory range and branch relaxation is normally handled by
  3149. the compiler or assembler.
  3150. </p>
  3151. <a name="index-_002d_002dstub_002dgroup_002dsize-on-C_002dSKY"></a>
  3152. </dd>
  3153. <dt><code>--stub-group-size=<var>N</var></code></dt>
  3154. <dd><p>This option allows finer control of linker branch stub creation.
  3155. It sets the maximum size of a group of input sections that can
  3156. be handled by one stub section. A negative value of <var>N</var> locates
  3157. stub sections after their branches, while a positive value allows stub
  3158. sections to appear either before or after the branches. Values of
  3159. &lsquo;<samp>1</samp>&rsquo; or &lsquo;<samp>-1</samp>&rsquo; indicate that the
  3160. linker should choose suitable defaults.
  3161. </p>
  3162. </dd>
  3163. </dl>
  3164. <a name="Options-specific-to-Motorola-68HC11-and-68HC12-targets"></a>
  3165. <h4 class="subsection">2.1.4 Options specific to Motorola 68HC11 and 68HC12 targets</h4>
  3166. <p>The 68HC11 and 68HC12 linkers support specific options to control the
  3167. memory bank switching mapping and trampoline code generation.
  3168. </p>
  3169. <dl compact="compact">
  3170. <dd>
  3171. <a name="index-_002d_002dno_002dtrampoline"></a>
  3172. </dd>
  3173. <dt><code>--no-trampoline</code></dt>
  3174. <dd><p>This option disables the generation of trampoline. By default a trampoline
  3175. is generated for each far function which is called using a <code>jsr</code>
  3176. instruction (this happens when a pointer to a far function is taken).
  3177. </p>
  3178. <a name="index-_002d_002dbank_002dwindow"></a>
  3179. </dd>
  3180. <dt><code>--bank-window <var>name</var></code></dt>
  3181. <dd><p>This option indicates to the linker the name of the memory region in
  3182. the &lsquo;<samp>MEMORY</samp>&rsquo; specification that describes the memory bank window.
  3183. The definition of such region is then used by the linker to compute
  3184. paging and addresses within the memory window.
  3185. </p>
  3186. </dd>
  3187. </dl>
  3188. <a name="Options-specific-to-Motorola-68K-target"></a>
  3189. <h4 class="subsection">2.1.5 Options specific to Motorola 68K target</h4>
  3190. <p>The following options are supported to control handling of GOT generation
  3191. when linking for 68K targets.
  3192. </p>
  3193. <dl compact="compact">
  3194. <dd>
  3195. <a name="index-_002d_002dgot"></a>
  3196. </dd>
  3197. <dt><code>--got=<var>type</var></code></dt>
  3198. <dd><p>This option tells the linker which GOT generation scheme to use.
  3199. <var>type</var> should be one of &lsquo;<samp>single</samp>&rsquo;, &lsquo;<samp>negative</samp>&rsquo;,
  3200. &lsquo;<samp>multigot</samp>&rsquo; or &lsquo;<samp>target</samp>&rsquo;. For more information refer to the
  3201. Info entry for <samp>ld</samp>.
  3202. </p>
  3203. </dd>
  3204. </dl>
  3205. <a name="Options-specific-to-MIPS-targets"></a>
  3206. <h4 class="subsection">2.1.6 Options specific to MIPS targets</h4>
  3207. <p>The following options are supported to control microMIPS instruction
  3208. generation and branch relocation checks for ISA mode transitions when
  3209. linking for MIPS targets.
  3210. </p>
  3211. <dl compact="compact">
  3212. <dd>
  3213. <a name="index-_002d_002dinsn32"></a>
  3214. </dd>
  3215. <dt><code>--insn32</code></dt>
  3216. <dd><a name="index-_002d_002dno_002dinsn32"></a>
  3217. </dd>
  3218. <dt><code>--no-insn32</code></dt>
  3219. <dd><p>These options control the choice of microMIPS instructions used in code
  3220. generated by the linker, such as that in the PLT or lazy binding stubs,
  3221. or in relaxation. If &lsquo;<samp>--insn32</samp>&rsquo; is used, then the linker only uses
  3222. 32-bit instruction encodings. By default or if &lsquo;<samp>--no-insn32</samp>&rsquo; is
  3223. used, all instruction encodings are used, including 16-bit ones where
  3224. possible.
  3225. </p>
  3226. <a name="index-_002d_002dignore_002dbranch_002disa"></a>
  3227. </dd>
  3228. <dt><code>--ignore-branch-isa</code></dt>
  3229. <dd><a name="index-_002d_002dno_002dignore_002dbranch_002disa"></a>
  3230. </dd>
  3231. <dt><code>--no-ignore-branch-isa</code></dt>
  3232. <dd><p>These options control branch relocation checks for invalid ISA mode
  3233. transitions. If &lsquo;<samp>--ignore-branch-isa</samp>&rsquo; is used, then the linker
  3234. accepts any branch relocations and any ISA mode transition required
  3235. is lost in relocation calculation, except for some cases of <code>BAL</code>
  3236. instructions which meet relaxation conditions and are converted to
  3237. equivalent <code>JALX</code> instructions as the associated relocation is
  3238. calculated. By default or if &lsquo;<samp>--no-ignore-branch-isa</samp>&rsquo; is used
  3239. a check is made causing the loss of an ISA mode transition to produce
  3240. an error.
  3241. </p>
  3242. <a name="index-_002d_002dcompact_002dbranches"></a>
  3243. </dd>
  3244. <dt><code>--compact-branches</code></dt>
  3245. <dd><a name="index-_002d_002dno_002dcompact_002dbranches"></a>
  3246. </dd>
  3247. <dt><code>--no-compact-branches</code></dt>
  3248. <dd><p>These options control the generation of compact instructions by the linker
  3249. in the PLT entries for MIPS R6.
  3250. </p>
  3251. </dd>
  3252. </dl>
  3253. <a name="Options-specific-to-PDP11-targets"></a>
  3254. <h4 class="subsection">2.1.7 Options specific to PDP11 targets</h4>
  3255. <p>For the pdp11-aout target, three variants of the output format can be
  3256. produced as selected by the following options. The default variant
  3257. for pdp11-aout is the &lsquo;<samp>--omagic</samp>&rsquo; option, whereas for other
  3258. targets &lsquo;<samp>--nmagic</samp>&rsquo; is the default. The &lsquo;<samp>--imagic</samp>&rsquo; option is
  3259. defined only for the pdp11-aout target, while the others are described
  3260. here as they apply to the pdp11-aout target.
  3261. </p>
  3262. <dl compact="compact">
  3263. <dd>
  3264. <a name="index-_002dN-1"></a>
  3265. </dd>
  3266. <dt><code>-N</code></dt>
  3267. <dd><a name="index-_002d_002domagic-1"></a>
  3268. </dd>
  3269. <dt><code>--omagic</code></dt>
  3270. <dd>
  3271. <p>Mark the output as <code>OMAGIC</code> (0407) in the <samp>a.out</samp> header to
  3272. indicate that the text segment is not to be write-protected and
  3273. shared. Since the text and data sections are both readable and
  3274. writable, the data section is allocated immediately contiguous after
  3275. the text segment. This is the oldest format for PDP11 executable
  3276. programs and is the default for <code>ld</code> on PDP11 Unix systems
  3277. from the beginning through 2.11BSD.
  3278. </p>
  3279. <a name="index-_002dn-1"></a>
  3280. </dd>
  3281. <dt><code>-n</code></dt>
  3282. <dd><a name="index-_002d_002dnmagic-1"></a>
  3283. </dd>
  3284. <dt><code>--nmagic</code></dt>
  3285. <dd>
  3286. <p>Mark the output as <code>NMAGIC</code> (0410) in the <samp>a.out</samp> header to
  3287. indicate that when the output file is executed, the text portion will
  3288. be read-only and shareable among all processes executing the same
  3289. file. This involves moving the data areas up to the first possible 8K
  3290. byte page boundary following the end of the text. This option creates
  3291. a <em>pure executable</em> format.
  3292. </p>
  3293. <a name="index-_002dz"></a>
  3294. </dd>
  3295. <dt><code>-z</code></dt>
  3296. <dd><a name="index-_002d_002dimagic"></a>
  3297. </dd>
  3298. <dt><code>--imagic</code></dt>
  3299. <dd>
  3300. <p>Mark the output as <code>IMAGIC</code> (0411) in the <samp>a.out</samp> header to
  3301. indicate that when the output file is executed, the program text and
  3302. data areas will be loaded into separate address spaces using the split
  3303. instruction and data space feature of the memory management unit in
  3304. larger models of the PDP11. This doubles the address space available
  3305. to the program. The text segment is again pure, write-protected, and
  3306. shareable. The only difference in the output format between this
  3307. option and the others, besides the magic number, is that both the text
  3308. and data sections start at location 0. The &lsquo;<samp>-z</samp>&rsquo; option selected
  3309. this format in 2.11BSD. This option creates a <em>separate
  3310. executable</em> format.
  3311. </p>
  3312. <a name="index-_002d_002dno_002domagic-1"></a>
  3313. </dd>
  3314. <dt><code>--no-omagic</code></dt>
  3315. <dd>
  3316. <p>Equivalent to &lsquo;<samp>--nmagic</samp>&rsquo; for pdp11-aout.
  3317. </p>
  3318. </dd>
  3319. </dl>
  3320. <hr>
  3321. <div class="header">
  3322. <p>
  3323. Next: <a href="Environment.html#Environment" accesskey="n" rel="next">Environment</a>, Up: <a href="Invocation.html#Invocation" accesskey="u" rel="up">Invocation</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
  3324. </div>
  3325. </body>
  3326. </html>