lexsup.c 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309
  1. /* Parse options for the GNU linker.
  2. Copyright (C) 1991-2022 Free Software Foundation, Inc.
  3. This file is part of the GNU Binutils.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #include "sysdep.h"
  17. #include "bfd.h"
  18. #include "bfdver.h"
  19. #include "libiberty.h"
  20. #include "filenames.h"
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <errno.h>
  24. #include "safe-ctype.h"
  25. #include "getopt.h"
  26. #include "bfdlink.h"
  27. #include "ctf-api.h"
  28. #include "ld.h"
  29. #include "ldmain.h"
  30. #include "ldmisc.h"
  31. #include "ldexp.h"
  32. #include "ldlang.h"
  33. #include <ldgram.h>
  34. #include "ldlex.h"
  35. #include "ldfile.h"
  36. #include "ldver.h"
  37. #include "ldemul.h"
  38. #include "demangle.h"
  39. #if BFD_SUPPORTS_PLUGINS
  40. #include "plugin.h"
  41. #endif /* BFD_SUPPORTS_PLUGINS */
  42. #ifndef PATH_SEPARATOR
  43. #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
  44. #define PATH_SEPARATOR ';'
  45. #else
  46. #define PATH_SEPARATOR ':'
  47. #endif
  48. #endif
  49. /* Somewhere above, sys/stat.h got included . . . . */
  50. #if !defined(S_ISDIR) && defined(S_IFDIR)
  51. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  52. #endif
  53. static void set_default_dirlist (char *);
  54. static void set_section_start (char *, char *);
  55. static void set_segment_start (const char *, char *);
  56. static void help (void);
  57. /* The long options. This structure is used for both the option
  58. parsing and the help text. */
  59. enum control_enum {
  60. /* Use one dash before long option name. */
  61. ONE_DASH = 1,
  62. /* Use two dashes before long option name. */
  63. TWO_DASHES = 2,
  64. /* Only accept two dashes before the long option name.
  65. This is an overloading of the use of this enum, since originally it
  66. was only intended to tell the --help display function how to display
  67. the long option name. This feature was added in order to resolve
  68. the confusion about the -omagic command line switch. Is it setting
  69. the output file name to "magic" or is it setting the NMAGIC flag on
  70. the output ? It has been decided that it is setting the output file
  71. name, and that if you want to set the NMAGIC flag you should use -N
  72. or --omagic. */
  73. EXACTLY_TWO_DASHES,
  74. /* Don't mention this option in --help output. */
  75. NO_HELP
  76. };
  77. struct ld_option
  78. {
  79. /* The long option information. */
  80. struct option opt;
  81. /* The short option with the same meaning ('\0' if none). */
  82. char shortopt;
  83. /* The name of the argument (NULL if none). */
  84. const char *arg;
  85. /* The documentation string. If this is NULL, this is a synonym for
  86. the previous option. */
  87. const char *doc;
  88. enum control_enum control;
  89. };
  90. static const struct ld_option ld_options[] =
  91. {
  92. { {NULL, required_argument, NULL, '\0'},
  93. 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
  94. ONE_DASH },
  95. { {"architecture", required_argument, NULL, 'A'},
  96. 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES },
  97. { {"format", required_argument, NULL, 'b'},
  98. 'b', N_("TARGET"), N_("Specify target for following input files"),
  99. TWO_DASHES },
  100. { {"mri-script", required_argument, NULL, 'c'},
  101. 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES },
  102. { {"dc", no_argument, NULL, 'd'},
  103. 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH },
  104. { {"dp", no_argument, NULL, 'd'},
  105. '\0', NULL, NULL, ONE_DASH },
  106. { {"dependency-file", required_argument, NULL, OPTION_DEPENDENCY_FILE},
  107. '\0', N_("FILE"), N_("Write dependency file"), TWO_DASHES },
  108. { {"force-group-allocation", no_argument, NULL,
  109. OPTION_FORCE_GROUP_ALLOCATION},
  110. '\0', NULL, N_("Force group members out of groups"), TWO_DASHES },
  111. { {"entry", required_argument, NULL, 'e'},
  112. 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
  113. { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
  114. 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES },
  115. { {"no-export-dynamic", no_argument, NULL, OPTION_NO_EXPORT_DYNAMIC},
  116. '\0', NULL, N_("Undo the effect of --export-dynamic"), TWO_DASHES },
  117. { {"enable-non-contiguous-regions", no_argument, NULL, OPTION_NON_CONTIGUOUS_REGIONS},
  118. '\0', NULL, N_("Enable support of non-contiguous memory regions"), TWO_DASHES },
  119. { {"enable-non-contiguous-regions-warnings", no_argument, NULL, OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS},
  120. '\0', NULL, N_("Enable warnings when --enable-non-contiguous-regions may cause unexpected behaviour"), TWO_DASHES },
  121. { {"EB", no_argument, NULL, OPTION_EB},
  122. '\0', NULL, N_("Link big-endian objects"), ONE_DASH },
  123. { {"EL", no_argument, NULL, OPTION_EL},
  124. '\0', NULL, N_("Link little-endian objects"), ONE_DASH },
  125. { {"auxiliary", required_argument, NULL, 'f'},
  126. 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
  127. TWO_DASHES },
  128. { {"filter", required_argument, NULL, 'F'},
  129. 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
  130. TWO_DASHES },
  131. { {NULL, no_argument, NULL, '\0'},
  132. 'g', NULL, N_("Ignored"), ONE_DASH },
  133. { {"gpsize", required_argument, NULL, 'G'},
  134. 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
  135. TWO_DASHES },
  136. { {"soname", required_argument, NULL, OPTION_SONAME},
  137. 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH },
  138. { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
  139. 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
  140. TWO_DASHES },
  141. { {"no-dynamic-linker", no_argument, NULL, OPTION_NO_DYNAMIC_LINKER},
  142. '\0', NULL, N_("Produce an executable with no program interpreter header"),
  143. TWO_DASHES },
  144. { {"library", required_argument, NULL, 'l'},
  145. 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES },
  146. { {"library-path", required_argument, NULL, 'L'},
  147. 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
  148. TWO_DASHES },
  149. { {"sysroot=<DIRECTORY>", required_argument, NULL, OPTION_SYSROOT},
  150. '\0', NULL, N_("Override the default sysroot location"), TWO_DASHES },
  151. { {NULL, required_argument, NULL, '\0'},
  152. 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH },
  153. { {"print-map", no_argument, NULL, 'M'},
  154. 'M', NULL, N_("Print map file on standard output"), TWO_DASHES },
  155. { {"nmagic", no_argument, NULL, 'n'},
  156. 'n', NULL, N_("Do not page align data"), TWO_DASHES },
  157. { {"omagic", no_argument, NULL, 'N'},
  158. 'N', NULL, N_("Do not page align data, do not make text readonly"),
  159. EXACTLY_TWO_DASHES },
  160. { {"no-omagic", no_argument, NULL, OPTION_NO_OMAGIC},
  161. '\0', NULL, N_("Page align data, make text readonly"),
  162. EXACTLY_TWO_DASHES },
  163. { {"output", required_argument, NULL, 'o'},
  164. 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES },
  165. { {NULL, required_argument, NULL, '\0'},
  166. 'O', NULL, N_("Optimize output file"), ONE_DASH },
  167. { {"out-implib", required_argument, NULL, OPTION_OUT_IMPLIB},
  168. '\0', N_("FILE"), N_("Generate import library"), TWO_DASHES },
  169. #if BFD_SUPPORTS_PLUGINS
  170. { {"plugin", required_argument, NULL, OPTION_PLUGIN},
  171. '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH },
  172. { {"plugin-opt", required_argument, NULL, OPTION_PLUGIN_OPT},
  173. '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH },
  174. { {"flto", optional_argument, NULL, OPTION_IGNORE},
  175. '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
  176. ONE_DASH },
  177. { {"flto-partition=", required_argument, NULL, OPTION_IGNORE},
  178. '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
  179. ONE_DASH },
  180. #else
  181. { {"plugin", required_argument, NULL, OPTION_IGNORE},
  182. '\0', N_("PLUGIN"), N_("Load named plugin (ignored)"), ONE_DASH },
  183. { {"plugin-opt", required_argument, NULL, OPTION_IGNORE},
  184. '\0', N_("ARG"), N_("Send arg to last-loaded plugin (ignored)"), ONE_DASH },
  185. #endif /* BFD_SUPPORTS_PLUGINS */
  186. { {"fuse-ld=", required_argument, NULL, OPTION_IGNORE},
  187. '\0', NULL, N_("Ignored for GCC linker option compatibility"),
  188. ONE_DASH },
  189. { {"map-whole-files", optional_argument, NULL, OPTION_IGNORE},
  190. '\0', NULL, N_("Ignored for gold option compatibility"),
  191. TWO_DASHES },
  192. { {"no-map-whole-files", optional_argument, NULL, OPTION_IGNORE},
  193. '\0', NULL, N_("Ignored for gold option compatibility"),
  194. TWO_DASHES },
  195. { {"Qy", no_argument, NULL, OPTION_IGNORE},
  196. '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH },
  197. { {"emit-relocs", no_argument, NULL, 'q'},
  198. 'q', NULL, "Generate relocations in final output", TWO_DASHES },
  199. { {"relocatable", no_argument, NULL, 'r'},
  200. 'r', NULL, N_("Generate relocatable output"), TWO_DASHES },
  201. { {NULL, no_argument, NULL, '\0'},
  202. 'i', NULL, NULL, ONE_DASH },
  203. { {"just-symbols", required_argument, NULL, 'R'},
  204. 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
  205. TWO_DASHES },
  206. { {"strip-all", no_argument, NULL, 's'},
  207. 's', NULL, N_("Strip all symbols"), TWO_DASHES },
  208. { {"strip-debug", no_argument, NULL, 'S'},
  209. 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES },
  210. { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED},
  211. '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES },
  212. { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED},
  213. '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES },
  214. { {"trace", no_argument, NULL, 't'},
  215. 't', NULL, N_("Trace file opens"), TWO_DASHES },
  216. { {"script", required_argument, NULL, 'T'},
  217. 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES },
  218. { {"default-script", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
  219. '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES },
  220. { {"dT", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
  221. '\0', NULL, NULL, ONE_DASH },
  222. { {"undefined", required_argument, NULL, 'u'},
  223. 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
  224. TWO_DASHES },
  225. { {"require-defined", required_argument, NULL, OPTION_REQUIRE_DEFINED_SYMBOL},
  226. '\0', N_("SYMBOL"), N_("Require SYMBOL be defined in the final output"),
  227. TWO_DASHES },
  228. { {"unique", optional_argument, NULL, OPTION_UNIQUE},
  229. '\0', N_("[=SECTION]"),
  230. N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES },
  231. { {"Ur", no_argument, NULL, OPTION_UR},
  232. '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH },
  233. { {"version", no_argument, NULL, OPTION_VERSION},
  234. 'v', NULL, N_("Print version information"), TWO_DASHES },
  235. { {NULL, no_argument, NULL, '\0'},
  236. 'V', NULL, N_("Print version and emulation information"), ONE_DASH },
  237. { {"discard-all", no_argument, NULL, 'x'},
  238. 'x', NULL, N_("Discard all local symbols"), TWO_DASHES },
  239. { {"discard-locals", no_argument, NULL, 'X'},
  240. 'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES },
  241. { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE},
  242. '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES },
  243. { {"trace-symbol", required_argument, NULL, 'y'},
  244. 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES },
  245. { {NULL, required_argument, NULL, '\0'},
  246. 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
  247. ONE_DASH },
  248. { {"start-group", no_argument, NULL, '('},
  249. '(', NULL, N_("Start a group"), TWO_DASHES },
  250. { {"end-group", no_argument, NULL, ')'},
  251. ')', NULL, N_("End a group"), TWO_DASHES },
  252. { {"accept-unknown-input-arch", no_argument, NULL,
  253. OPTION_ACCEPT_UNKNOWN_INPUT_ARCH},
  254. '\0', NULL,
  255. N_("Accept input files whose architecture cannot be determined"),
  256. TWO_DASHES },
  257. { {"no-accept-unknown-input-arch", no_argument, NULL,
  258. OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH},
  259. '\0', NULL, N_("Reject input files whose architecture is unknown"),
  260. TWO_DASHES },
  261. /* The next two options are deprecated because of their similarity to
  262. --as-needed and --no-as-needed. They have been replaced by
  263. --copy-dt-needed-entries and --no-copy-dt-needed-entries. */
  264. { {"add-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
  265. '\0', NULL, NULL, NO_HELP },
  266. { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
  267. '\0', NULL, NULL, NO_HELP },
  268. { {"as-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_REGULAR},
  269. '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"),
  270. TWO_DASHES },
  271. { {"no-as-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR},
  272. '\0', NULL, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n"
  273. " the command line"),
  274. TWO_DASHES },
  275. { {"assert", required_argument, NULL, OPTION_ASSERT},
  276. '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
  277. { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
  278. '\0', NULL, N_("Link against shared libraries"), ONE_DASH },
  279. { {"dy", no_argument, NULL, OPTION_CALL_SHARED},
  280. '\0', NULL, NULL, ONE_DASH },
  281. { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
  282. '\0', NULL, NULL, ONE_DASH },
  283. { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
  284. '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH },
  285. { {"dn", no_argument, NULL, OPTION_NON_SHARED},
  286. '\0', NULL, NULL, ONE_DASH },
  287. { {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
  288. '\0', NULL, NULL, ONE_DASH },
  289. { {"static", no_argument, NULL, OPTION_NON_SHARED},
  290. '\0', NULL, NULL, ONE_DASH },
  291. { {"Bno-symbolic", no_argument, NULL, OPTION_NO_SYMBOLIC},
  292. '\0', NULL, N_("Don't bind global references locally"), ONE_DASH },
  293. { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
  294. '\0', NULL, N_("Bind global references locally"), ONE_DASH },
  295. { {"Bsymbolic-functions", no_argument, NULL, OPTION_SYMBOLIC_FUNCTIONS},
  296. '\0', NULL, N_("Bind global function references locally"), ONE_DASH },
  297. { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS},
  298. '\0', NULL, N_("Check section addresses for overlaps (default)"),
  299. TWO_DASHES },
  300. { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS},
  301. '\0', NULL, N_("Do not check section addresses for overlaps"),
  302. TWO_DASHES },
  303. { {"copy-dt-needed-entries", no_argument, NULL,
  304. OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
  305. '\0', NULL, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"),
  306. TWO_DASHES },
  307. { {"no-copy-dt-needed-entries", no_argument, NULL,
  308. OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
  309. '\0', NULL, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"),
  310. TWO_DASHES },
  311. { {"cref", no_argument, NULL, OPTION_CREF},
  312. '\0', NULL, N_("Output cross reference table"), TWO_DASHES },
  313. { {"defsym", required_argument, NULL, OPTION_DEFSYM},
  314. '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES },
  315. { {"demangle", optional_argument, NULL, OPTION_DEMANGLE},
  316. '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
  317. TWO_DASHES },
  318. { {"disable-multiple-abs-defs", no_argument, NULL,
  319. OPTION_DISABLE_MULTIPLE_DEFS_ABS},
  320. '\0', NULL, N_("Do not allow multiple definitions with symbols included\n"
  321. " in filename invoked by -R "
  322. "or --just-symbols"),
  323. TWO_DASHES},
  324. { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
  325. '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES},
  326. { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL},
  327. '\0', NULL, N_("Treat warnings as errors"),
  328. TWO_DASHES },
  329. { {"no-fatal-warnings", no_argument, NULL, OPTION_NO_WARN_FATAL},
  330. '\0', NULL, N_("Do not treat warnings as errors (default)"),
  331. TWO_DASHES },
  332. { {"fini", required_argument, NULL, OPTION_FINI},
  333. '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH },
  334. { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX},
  335. '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES},
  336. { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS},
  337. '\0', NULL, N_("Remove unused sections (on some targets)"),
  338. TWO_DASHES },
  339. { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS},
  340. '\0', NULL, N_("Don't remove unused sections (default)"),
  341. TWO_DASHES },
  342. { {"print-gc-sections", no_argument, NULL, OPTION_PRINT_GC_SECTIONS},
  343. '\0', NULL, N_("List removed unused sections on stderr"),
  344. TWO_DASHES },
  345. { {"no-print-gc-sections", no_argument, NULL, OPTION_NO_PRINT_GC_SECTIONS},
  346. '\0', NULL, N_("Do not list removed unused sections"),
  347. TWO_DASHES },
  348. { {"gc-keep-exported", no_argument, NULL, OPTION_GC_KEEP_EXPORTED},
  349. '\0', NULL, N_("Keep exported symbols when removing unused sections"),
  350. TWO_DASHES },
  351. { {"hash-size=<NUMBER>", required_argument, NULL, OPTION_HASH_SIZE},
  352. '\0', NULL, N_("Set default hash table size close to <NUMBER>"),
  353. TWO_DASHES },
  354. { {"help", no_argument, NULL, OPTION_HELP},
  355. '\0', NULL, N_("Print option help"), TWO_DASHES },
  356. { {"init", required_argument, NULL, OPTION_INIT},
  357. '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH },
  358. { {"Map", required_argument, NULL, OPTION_MAP},
  359. '\0', N_("FILE/DIR"), N_("Write a linker map to FILE or DIR/<outputname>.map"), ONE_DASH },
  360. { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON},
  361. '\0', NULL, N_("Do not define Common storage"), TWO_DASHES },
  362. { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE },
  363. '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES },
  364. { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
  365. '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES },
  366. { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED},
  367. '\0', NULL, N_("Do not allow unresolved references in object files"),
  368. TWO_DASHES },
  369. { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED},
  370. '\0', NULL, N_("Allow unresolved references in shared libraries"),
  371. TWO_DASHES },
  372. { {"no-allow-shlib-undefined", no_argument, NULL,
  373. OPTION_NO_ALLOW_SHLIB_UNDEFINED},
  374. '\0', NULL, N_("Do not allow unresolved references in shared libs"),
  375. TWO_DASHES },
  376. { {"allow-multiple-definition", no_argument, NULL,
  377. OPTION_ALLOW_MULTIPLE_DEFINITION},
  378. '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES },
  379. #if SUPPORT_ERROR_HANDLING_SCRIPT
  380. { {"error-handling-script", required_argument, NULL,
  381. OPTION_ERROR_HANDLING_SCRIPT},
  382. '\0', N_("SCRIPT"), N_("Provide a script to help with undefined symbol errors"), TWO_DASHES},
  383. #endif
  384. { {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION},
  385. '\0', NULL, N_("Disallow undefined version"), TWO_DASHES },
  386. { {"default-symver", no_argument, NULL, OPTION_DEFAULT_SYMVER},
  387. '\0', NULL, N_("Create default symbol version"), TWO_DASHES },
  388. { {"default-imported-symver", no_argument, NULL,
  389. OPTION_DEFAULT_IMPORTED_SYMVER},
  390. '\0', NULL, N_("Create default symbol version for imported symbols"),
  391. TWO_DASHES },
  392. { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH},
  393. '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES},
  394. { {"no-warn-search-mismatch", no_argument, NULL,
  395. OPTION_NO_WARN_SEARCH_MISMATCH},
  396. '\0', NULL, N_("Don't warn on finding an incompatible library"),
  397. TWO_DASHES},
  398. { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
  399. '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES },
  400. { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
  401. '\0', NULL, N_("Create an output file even if errors occur"),
  402. TWO_DASHES },
  403. { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
  404. '\0', NULL, NULL, NO_HELP },
  405. { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB},
  406. '\0', NULL, N_("Only use library directories specified on\n"
  407. " the command line"),
  408. ONE_DASH },
  409. { {"oformat", required_argument, NULL, OPTION_OFORMAT},
  410. '\0', N_("TARGET"), N_("Specify target of output file"),
  411. EXACTLY_TWO_DASHES },
  412. { {"print-output-format", no_argument, NULL, OPTION_PRINT_OUTPUT_FORMAT},
  413. '\0', NULL, N_("Print default output format"), TWO_DASHES },
  414. { {"print-sysroot", no_argument, NULL, OPTION_PRINT_SYSROOT},
  415. '\0', NULL, N_("Print current sysroot"), TWO_DASHES },
  416. { {"qmagic", no_argument, NULL, OPTION_IGNORE},
  417. '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
  418. { {"reduce-memory-overheads", no_argument, NULL,
  419. OPTION_REDUCE_MEMORY_OVERHEADS},
  420. '\0', NULL, N_("Reduce memory overheads, possibly taking much longer"),
  421. TWO_DASHES },
  422. { {"max-cache-size=SIZE", required_argument, NULL,
  423. OPTION_MAX_CACHE_SIZE},
  424. '\0', NULL, N_("Set the maximum cache size to SIZE bytes"),
  425. TWO_DASHES },
  426. { {"relax", no_argument, NULL, OPTION_RELAX},
  427. '\0', NULL, N_("Reduce code size by using target specific optimizations"), TWO_DASHES },
  428. { {"no-relax", no_argument, NULL, OPTION_NO_RELAX},
  429. '\0', NULL, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES },
  430. { {"retain-symbols-file", required_argument, NULL,
  431. OPTION_RETAIN_SYMBOLS_FILE},
  432. '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES },
  433. { {"rpath", required_argument, NULL, OPTION_RPATH},
  434. '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH },
  435. { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK},
  436. '\0', N_("PATH"), N_("Set link time shared library search path"),
  437. ONE_DASH },
  438. { {"shared", no_argument, NULL, OPTION_SHARED},
  439. '\0', NULL, N_("Create a shared library"), ONE_DASH },
  440. { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */
  441. '\0', NULL, NULL, ONE_DASH },
  442. { {"pie", no_argument, NULL, OPTION_PIE},
  443. '\0', NULL, N_("Create a position independent executable"), ONE_DASH },
  444. { {"pic-executable", no_argument, NULL, OPTION_PIE},
  445. '\0', NULL, NULL, TWO_DASHES },
  446. { {"no-pie", no_argument, NULL, OPTION_NO_PIE},
  447. '\0', NULL, N_("Create a position dependent executable (default)"), ONE_DASH },
  448. { {"sort-common", optional_argument, NULL, OPTION_SORT_COMMON},
  449. '\0', N_("[=ascending|descending]"),
  450. N_("Sort common symbols by alignment [in specified order]"),
  451. TWO_DASHES },
  452. { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
  453. '\0', NULL, NULL, NO_HELP },
  454. { {"sort-section", required_argument, NULL, OPTION_SORT_SECTION},
  455. '\0', N_("name|alignment"),
  456. N_("Sort sections by name or maximum alignment"), TWO_DASHES },
  457. { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS},
  458. '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
  459. TWO_DASHES },
  460. { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE},
  461. '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
  462. TWO_DASHES },
  463. { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC},
  464. '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
  465. TWO_DASHES },
  466. { {"stats", no_argument, NULL, OPTION_STATS},
  467. '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES },
  468. { {"target-help", no_argument, NULL, OPTION_TARGET_HELP},
  469. '\0', NULL, N_("Display target specific options"), TWO_DASHES },
  470. { {"task-link", required_argument, NULL, OPTION_TASK_LINK},
  471. '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES },
  472. { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
  473. '\0', NULL, N_("Use same format as native linker"), TWO_DASHES },
  474. { {"section-start", required_argument, NULL, OPTION_SECTION_START},
  475. '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
  476. TWO_DASHES },
  477. { {"Tbss", required_argument, NULL, OPTION_TBSS},
  478. '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH },
  479. { {"Tdata", required_argument, NULL, OPTION_TDATA},
  480. '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH },
  481. { {"Ttext", required_argument, NULL, OPTION_TTEXT},
  482. '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH },
  483. { {"Ttext-segment", required_argument, NULL, OPTION_TTEXT_SEGMENT},
  484. '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH },
  485. { {"Trodata-segment", required_argument, NULL, OPTION_TRODATA_SEGMENT},
  486. '\0', N_("ADDRESS"), N_("Set address of rodata segment"), ONE_DASH },
  487. { {"Tldata-segment", required_argument, NULL, OPTION_TLDATA_SEGMENT},
  488. '\0', N_("ADDRESS"), N_("Set address of ldata segment"), ONE_DASH },
  489. { {"unresolved-symbols=<method>", required_argument, NULL,
  490. OPTION_UNRESOLVED_SYMBOLS},
  491. '\0', NULL, N_("How to handle unresolved symbols. <method> is:\n"
  492. " ignore-all, report-all, ignore-in-object-files,\n"
  493. " ignore-in-shared-libs"),
  494. TWO_DASHES },
  495. { {"verbose", optional_argument, NULL, OPTION_VERBOSE},
  496. '\0', N_("[=NUMBER]"),
  497. N_("Output lots of information during link"), TWO_DASHES },
  498. { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */
  499. '\0', NULL, NULL, NO_HELP },
  500. { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT },
  501. '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES },
  502. { {"version-exports-section", required_argument, NULL,
  503. OPTION_VERSION_EXPORTS_SECTION },
  504. '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
  505. " SYMBOL as the version."),
  506. TWO_DASHES },
  507. { {"dynamic-list-data", no_argument, NULL, OPTION_DYNAMIC_LIST_DATA},
  508. '\0', NULL, N_("Add data symbols to dynamic list"), TWO_DASHES },
  509. { {"dynamic-list-cpp-new", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_NEW},
  510. '\0', NULL, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES },
  511. { {"dynamic-list-cpp-typeinfo", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_TYPEINFO},
  512. '\0', NULL, N_("Use C++ typeinfo dynamic list"), TWO_DASHES },
  513. { {"dynamic-list", required_argument, NULL, OPTION_DYNAMIC_LIST},
  514. '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES },
  515. { {"export-dynamic-symbol", required_argument, NULL, OPTION_EXPORT_DYNAMIC_SYMBOL},
  516. '\0', N_("SYMBOL"), N_("Export the specified symbol"), EXACTLY_TWO_DASHES },
  517. { {"export-dynamic-symbol-list", required_argument, NULL, OPTION_EXPORT_DYNAMIC_SYMBOL_LIST},
  518. '\0', N_("FILE"), N_("Read export dynamic symbol list"), EXACTLY_TWO_DASHES },
  519. { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
  520. '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
  521. { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
  522. '\0', NULL, N_("Warn if global constructors/destructors are seen"),
  523. TWO_DASHES },
  524. { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
  525. '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
  526. { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
  527. '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
  528. { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
  529. '\0', NULL, N_("Warn if start of section changes due to alignment"),
  530. TWO_DASHES },
  531. { {"warn-textrel", no_argument, NULL, OPTION_WARN_TEXTREL},
  532. '\0', NULL,
  533. #if DEFAULT_LD_TEXTREL_CHECK_WARNING
  534. N_("Warn if output has DT_TEXTREL (default)"),
  535. #else
  536. N_("Warn if output has DT_TEXTREL"),
  537. #endif
  538. TWO_DASHES },
  539. { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_TEXTREL},
  540. '\0', NULL, NULL, NO_HELP },
  541. { {"warn-alternate-em", no_argument, NULL, OPTION_WARN_ALTERNATE_EM},
  542. '\0', NULL, N_("Warn if an object has alternate ELF machine code"),
  543. TWO_DASHES },
  544. { {"warn-unresolved-symbols", no_argument, NULL,
  545. OPTION_WARN_UNRESOLVED_SYMBOLS},
  546. '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES },
  547. { {"error-unresolved-symbols", no_argument, NULL,
  548. OPTION_ERROR_UNRESOLVED_SYMBOLS},
  549. '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES },
  550. { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
  551. '\0', NULL, N_("Include all objects from following archives"),
  552. TWO_DASHES },
  553. { {"wrap", required_argument, NULL, OPTION_WRAP},
  554. '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES },
  555. { {"ignore-unresolved-symbol", required_argument, NULL,
  556. OPTION_IGNORE_UNRESOLVED_SYMBOL},
  557. '\0', N_("SYMBOL"),
  558. N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
  559. { {"push-state", no_argument, NULL, OPTION_PUSH_STATE},
  560. '\0', NULL, N_("Push state of flags governing input file handling"),
  561. TWO_DASHES },
  562. { {"pop-state", no_argument, NULL, OPTION_POP_STATE},
  563. '\0', NULL, N_("Pop state of flags governing input file handling"),
  564. TWO_DASHES },
  565. { {"print-memory-usage", no_argument, NULL, OPTION_PRINT_MEMORY_USAGE},
  566. '\0', NULL, N_("Report target memory usage"), TWO_DASHES },
  567. { {"orphan-handling", required_argument, NULL, OPTION_ORPHAN_HANDLING},
  568. '\0', N_("=MODE"), N_("Control how orphan sections are handled."),
  569. TWO_DASHES },
  570. { {"print-map-discarded", no_argument, NULL, OPTION_PRINT_MAP_DISCARDED},
  571. '\0', NULL, N_("Show discarded sections in map file output (default)"),
  572. TWO_DASHES },
  573. { {"no-print-map-discarded", no_argument, NULL, OPTION_NO_PRINT_MAP_DISCARDED},
  574. '\0', NULL, N_("Do not show discarded sections in map file output"),
  575. TWO_DASHES },
  576. { {"ctf-variables", no_argument, NULL, OPTION_CTF_VARIABLES},
  577. '\0', NULL, N_("Emit names and types of static variables in CTF"),
  578. TWO_DASHES },
  579. { {"no-ctf-variables", no_argument, NULL, OPTION_NO_CTF_VARIABLES},
  580. '\0', NULL, N_("Do not emit names and types of static variables in CTF"),
  581. TWO_DASHES },
  582. { {"ctf-share-types=<method>", required_argument, NULL,
  583. OPTION_CTF_SHARE_TYPES},
  584. '\0', NULL, N_("How to share CTF types between translation units.\n"
  585. " <method> is: share-unconflicted (default),\n"
  586. " share-duplicated"),
  587. TWO_DASHES },
  588. };
  589. #define OPTION_COUNT ARRAY_SIZE (ld_options)
  590. void
  591. parse_args (unsigned argc, char **argv)
  592. {
  593. unsigned i;
  594. int is, il, irl;
  595. int ingroup = 0;
  596. char *default_dirlist = NULL;
  597. char *shortopts;
  598. struct option *longopts;
  599. struct option *really_longopts;
  600. int last_optind;
  601. enum symbolic_enum
  602. {
  603. symbolic_unset = 0,
  604. symbolic,
  605. symbolic_functions,
  606. } opt_symbolic = symbolic_unset;
  607. enum dynamic_list_enum
  608. {
  609. dynamic_list_unset = 0,
  610. dynamic_list_data,
  611. dynamic_list
  612. } opt_dynamic_list = dynamic_list_unset;
  613. struct bfd_elf_dynamic_list *export_list = NULL;
  614. shortopts = (char *) xmalloc (OPTION_COUNT * 3 + 2);
  615. longopts = (struct option *)
  616. xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1));
  617. really_longopts = (struct option *)
  618. xmalloc (sizeof (*really_longopts) * (OPTION_COUNT + 1));
  619. /* Starting the short option string with '-' is for programs that
  620. expect options and other ARGV-elements in any order and that care about
  621. the ordering of the two. We describe each non-option ARGV-element
  622. as if it were the argument of an option with character code 1. */
  623. shortopts[0] = '-';
  624. is = 1;
  625. il = 0;
  626. irl = 0;
  627. for (i = 0; i < OPTION_COUNT; i++)
  628. {
  629. if (ld_options[i].shortopt != '\0')
  630. {
  631. shortopts[is] = ld_options[i].shortopt;
  632. ++is;
  633. if (ld_options[i].opt.has_arg == required_argument
  634. || ld_options[i].opt.has_arg == optional_argument)
  635. {
  636. shortopts[is] = ':';
  637. ++is;
  638. if (ld_options[i].opt.has_arg == optional_argument)
  639. {
  640. shortopts[is] = ':';
  641. ++is;
  642. }
  643. }
  644. }
  645. if (ld_options[i].opt.name != NULL)
  646. {
  647. if (ld_options[i].control == EXACTLY_TWO_DASHES)
  648. {
  649. really_longopts[irl] = ld_options[i].opt;
  650. ++irl;
  651. }
  652. else
  653. {
  654. longopts[il] = ld_options[i].opt;
  655. ++il;
  656. }
  657. }
  658. }
  659. shortopts[is] = '\0';
  660. longopts[il].name = NULL;
  661. really_longopts[irl].name = NULL;
  662. ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts);
  663. /* The -G option is ambiguous on different platforms. Sometimes it
  664. specifies the largest data size to put into the small data
  665. section. Sometimes it is equivalent to --shared. Unfortunately,
  666. the first form takes an argument, while the second does not.
  667. We need to permit the --shared form because on some platforms,
  668. such as Solaris, gcc -shared will pass -G to the linker.
  669. To permit either usage, we look through the argument list. If we
  670. find -G not followed by a number, we change it into --shared.
  671. This will work for most normal cases. */
  672. for (i = 1; i < argc; i++)
  673. if (strcmp (argv[i], "-G") == 0
  674. && (i + 1 >= argc
  675. || ! ISDIGIT (argv[i + 1][0])))
  676. argv[i] = (char *) "--shared";
  677. /* Because we permit long options to start with a single dash, and
  678. we have a --library option, and the -l option is conventionally
  679. used with an immediately following argument, we can have bad
  680. results if somebody tries to use -l with a library whose name
  681. happens to start with "ibrary", as in -li. We avoid problems by
  682. simply turning -l into --library. This means that users will
  683. have to use two dashes in order to use --library, which is OK
  684. since that's how it is documented.
  685. FIXME: It's possible that this problem can arise for other short
  686. options as well, although the user does always have the recourse
  687. of adding a space between the option and the argument. */
  688. for (i = 1; i < argc; i++)
  689. {
  690. if (argv[i][0] == '-'
  691. && argv[i][1] == 'l'
  692. && argv[i][2] != '\0')
  693. {
  694. char *n;
  695. n = (char *) xmalloc (strlen (argv[i]) + 20);
  696. sprintf (n, "--library=%s", argv[i] + 2);
  697. argv[i] = n;
  698. }
  699. }
  700. last_optind = -1;
  701. while (1)
  702. {
  703. int longind = 0;
  704. int optc;
  705. static unsigned int defsym_count;
  706. /* Using last_optind lets us avoid calling ldemul_parse_args
  707. multiple times on a single option, which would lead to
  708. confusion in the internal static variables maintained by
  709. getopt. This could otherwise happen for an argument like
  710. -nx, in which the -n is parsed as a single option, and we
  711. loop around to pick up the -x. */
  712. if (optind != last_optind)
  713. if (ldemul_parse_args (argc, argv))
  714. continue;
  715. /* getopt_long_only is like getopt_long, but '-' as well as '--'
  716. can indicate a long option. */
  717. opterr = 0;
  718. last_optind = optind;
  719. optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
  720. if (optc == '?')
  721. {
  722. optind = last_optind;
  723. optc = getopt_long (argc, argv, "-", really_longopts, &longind);
  724. }
  725. /* Attempt to detect grouped short options, eg: "-non-start".
  726. Accepting such options is error prone as it is not clear if the user
  727. intended "-n -o n-start" or "--non-start". */
  728. else if (longind == 0 /* This is a short option. */
  729. && optc > 32 /* It is a valid option. */
  730. /* The character is not the second character of argv[last_optind]. */
  731. && optc != argv[last_optind][1])
  732. {
  733. if (optarg)
  734. einfo (_("%F%P: Error: unable to disambiguate: %s (did you mean -%s ?)\n"),
  735. argv[last_optind], argv[last_optind]);
  736. else
  737. einfo (_("%P: Warning: grouped short command line options are deprecated: %s\n"), argv[last_optind]);
  738. }
  739. if (ldemul_handle_option (optc))
  740. continue;
  741. if (optc == -1)
  742. break;
  743. switch (optc)
  744. {
  745. case '?':
  746. {
  747. /* If the last word on the command line is an option that
  748. requires an argument, getopt will refuse to recognise it.
  749. Try to catch such options here and issue a more helpful
  750. error message than just "unrecognized option". */
  751. int opt;
  752. for (opt = ARRAY_SIZE (ld_options); opt--;)
  753. if (ld_options[opt].opt.has_arg == required_argument
  754. /* FIXME: There are a few short options that do not
  755. have long equivalents, but which require arguments.
  756. We should handle them too. */
  757. && ld_options[opt].opt.name != NULL
  758. && strcmp (argv[last_optind] + ld_options[opt].control, ld_options[opt].opt.name) == 0)
  759. {
  760. einfo (_("%P: %s: missing argument\n"), argv[last_optind]);
  761. break;
  762. }
  763. if (opt == -1)
  764. einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]);
  765. }
  766. /* Fall through. */
  767. default:
  768. einfo (_("%F%P: use the --help option for usage information\n"));
  769. break;
  770. case 1: /* File name. */
  771. lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL);
  772. break;
  773. case OPTION_IGNORE:
  774. break;
  775. case 'a':
  776. /* For HP/UX compatibility. Actually -a shared should mean
  777. ``use only shared libraries'' but, then, we don't
  778. currently support shared libraries on HP/UX anyhow. */
  779. if (strcmp (optarg, "archive") == 0)
  780. input_flags.dynamic = false;
  781. else if (strcmp (optarg, "shared") == 0
  782. || strcmp (optarg, "default") == 0)
  783. input_flags.dynamic = true;
  784. else
  785. einfo (_("%F%P: unrecognized -a option `%s'\n"), optarg);
  786. break;
  787. case OPTION_ASSERT:
  788. /* FIXME: We just ignore these, but we should handle them. */
  789. if (strcmp (optarg, "definitions") == 0)
  790. ;
  791. else if (strcmp (optarg, "nodefinitions") == 0)
  792. ;
  793. else if (strcmp (optarg, "nosymbolic") == 0)
  794. ;
  795. else if (strcmp (optarg, "pure-text") == 0)
  796. ;
  797. else
  798. einfo (_("%F%P: unrecognized -assert option `%s'\n"), optarg);
  799. break;
  800. case 'A':
  801. ldfile_add_arch (optarg);
  802. break;
  803. case 'b':
  804. lang_add_target (optarg);
  805. break;
  806. case 'c':
  807. ldfile_open_command_file (optarg);
  808. parser_input = input_mri_script;
  809. yyparse ();
  810. break;
  811. case OPTION_CALL_SHARED:
  812. input_flags.dynamic = true;
  813. break;
  814. case OPTION_NON_SHARED:
  815. input_flags.dynamic = false;
  816. break;
  817. case OPTION_CREF:
  818. command_line.cref = true;
  819. link_info.notice_all = true;
  820. break;
  821. case 'd':
  822. command_line.force_common_definition = true;
  823. break;
  824. case OPTION_FORCE_GROUP_ALLOCATION:
  825. command_line.force_group_allocation = true;
  826. break;
  827. case OPTION_DEFSYM:
  828. lex_string = optarg;
  829. lex_redirect (optarg, "--defsym", ++defsym_count);
  830. parser_input = input_defsym;
  831. yyparse ();
  832. lex_string = NULL;
  833. break;
  834. case OPTION_DEMANGLE:
  835. demangling = true;
  836. if (optarg != NULL)
  837. {
  838. enum demangling_styles style;
  839. style = cplus_demangle_name_to_style (optarg);
  840. if (style == unknown_demangling)
  841. einfo (_("%F%P: unknown demangling style `%s'\n"),
  842. optarg);
  843. cplus_demangle_set_style (style);
  844. }
  845. break;
  846. case 'I': /* Used on Solaris. */
  847. case OPTION_DYNAMIC_LINKER:
  848. command_line.interpreter = optarg;
  849. link_info.nointerp = 0;
  850. break;
  851. case OPTION_NO_DYNAMIC_LINKER:
  852. link_info.nointerp = 1;
  853. break;
  854. case OPTION_SYSROOT:
  855. /* Already handled in ldmain.c. */
  856. break;
  857. case OPTION_EB:
  858. command_line.endian = ENDIAN_BIG;
  859. break;
  860. case OPTION_EL:
  861. command_line.endian = ENDIAN_LITTLE;
  862. break;
  863. case OPTION_EMBEDDED_RELOCS:
  864. command_line.embedded_relocs = true;
  865. break;
  866. case OPTION_EXPORT_DYNAMIC:
  867. case 'E': /* HP/UX compatibility. */
  868. link_info.export_dynamic = true;
  869. break;
  870. case OPTION_NO_EXPORT_DYNAMIC:
  871. link_info.export_dynamic = false;
  872. break;
  873. case OPTION_NON_CONTIGUOUS_REGIONS:
  874. link_info.non_contiguous_regions = true;
  875. break;
  876. case OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS:
  877. link_info.non_contiguous_regions_warnings = true;
  878. break;
  879. case 'e':
  880. lang_add_entry (optarg, true);
  881. break;
  882. case 'f':
  883. if (command_line.auxiliary_filters == NULL)
  884. {
  885. command_line.auxiliary_filters = (char **)
  886. xmalloc (2 * sizeof (char *));
  887. command_line.auxiliary_filters[0] = optarg;
  888. command_line.auxiliary_filters[1] = NULL;
  889. }
  890. else
  891. {
  892. int c;
  893. char **p;
  894. c = 0;
  895. for (p = command_line.auxiliary_filters; *p != NULL; p++)
  896. ++c;
  897. command_line.auxiliary_filters = (char **)
  898. xrealloc (command_line.auxiliary_filters,
  899. (c + 2) * sizeof (char *));
  900. command_line.auxiliary_filters[c] = optarg;
  901. command_line.auxiliary_filters[c + 1] = NULL;
  902. }
  903. break;
  904. case 'F':
  905. command_line.filter_shlib = optarg;
  906. break;
  907. case OPTION_FORCE_EXE_SUFFIX:
  908. command_line.force_exe_suffix = true;
  909. break;
  910. case 'G':
  911. {
  912. char *end;
  913. g_switch_value = strtoul (optarg, &end, 0);
  914. if (*end)
  915. einfo (_("%F%P: invalid number `%s'\n"), optarg);
  916. }
  917. break;
  918. case 'g':
  919. /* Ignore. */
  920. break;
  921. case OPTION_GC_SECTIONS:
  922. link_info.gc_sections = true;
  923. break;
  924. case OPTION_PRINT_GC_SECTIONS:
  925. link_info.print_gc_sections = true;
  926. break;
  927. case OPTION_GC_KEEP_EXPORTED:
  928. link_info.gc_keep_exported = true;
  929. break;
  930. case OPTION_HELP:
  931. help ();
  932. xexit (0);
  933. break;
  934. case 'L':
  935. ldfile_add_library_path (optarg, true);
  936. break;
  937. case 'l':
  938. lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL);
  939. break;
  940. case 'M':
  941. config.map_filename = "-";
  942. break;
  943. case 'm':
  944. /* Ignore. Was handled in a pre-parse. */
  945. break;
  946. case OPTION_MAP:
  947. config.map_filename = optarg;
  948. break;
  949. case 'N':
  950. config.text_read_only = false;
  951. config.magic_demand_paged = false;
  952. input_flags.dynamic = false;
  953. break;
  954. case OPTION_NO_OMAGIC:
  955. config.text_read_only = true;
  956. config.magic_demand_paged = true;
  957. /* NB/ Does not set input_flags.dynamic to TRUE.
  958. Use --call-shared or -Bdynamic for this. */
  959. break;
  960. case 'n':
  961. config.text_read_only = true;
  962. config.magic_demand_paged = false;
  963. input_flags.dynamic = false;
  964. break;
  965. case OPTION_NO_DEFINE_COMMON:
  966. link_info.inhibit_common_definition = true;
  967. break;
  968. case OPTION_NO_DEMANGLE:
  969. demangling = false;
  970. break;
  971. case OPTION_NO_GC_SECTIONS:
  972. link_info.gc_sections = false;
  973. break;
  974. case OPTION_NO_PRINT_GC_SECTIONS:
  975. link_info.print_gc_sections = false;
  976. break;
  977. case OPTION_NO_KEEP_MEMORY:
  978. link_info.keep_memory = false;
  979. break;
  980. case OPTION_NO_UNDEFINED:
  981. link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
  982. break;
  983. case OPTION_ALLOW_SHLIB_UNDEFINED:
  984. link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
  985. break;
  986. case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
  987. link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
  988. break;
  989. case OPTION_UNRESOLVED_SYMBOLS:
  990. if (strcmp (optarg, "ignore-all") == 0)
  991. {
  992. link_info.unresolved_syms_in_objects = RM_IGNORE;
  993. link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
  994. }
  995. else if (strcmp (optarg, "report-all") == 0)
  996. {
  997. link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
  998. link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
  999. }
  1000. else if (strcmp (optarg, "ignore-in-object-files") == 0)
  1001. {
  1002. link_info.unresolved_syms_in_objects = RM_IGNORE;
  1003. link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
  1004. }
  1005. else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
  1006. {
  1007. link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
  1008. link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
  1009. }
  1010. else
  1011. einfo (_("%F%P: bad --unresolved-symbols option: %s\n"), optarg);
  1012. break;
  1013. case OPTION_WARN_UNRESOLVED_SYMBOLS:
  1014. link_info.warn_unresolved_syms = true;
  1015. break;
  1016. case OPTION_ERROR_UNRESOLVED_SYMBOLS:
  1017. link_info.warn_unresolved_syms = false;
  1018. break;
  1019. case OPTION_ALLOW_MULTIPLE_DEFINITION:
  1020. link_info.allow_multiple_definition = true;
  1021. break;
  1022. #if SUPPORT_ERROR_HANDLING_SCRIPT
  1023. case OPTION_ERROR_HANDLING_SCRIPT:
  1024. /* FIXME: Should we warn if the script is being overridden by another ?
  1025. Or maybe they should be chained together ? */
  1026. error_handling_script = optarg;
  1027. break;
  1028. #endif
  1029. case OPTION_NO_UNDEFINED_VERSION:
  1030. link_info.allow_undefined_version = false;
  1031. break;
  1032. case OPTION_DEFAULT_SYMVER:
  1033. link_info.create_default_symver = true;
  1034. break;
  1035. case OPTION_DEFAULT_IMPORTED_SYMVER:
  1036. link_info.default_imported_symver = true;
  1037. break;
  1038. case OPTION_NO_WARN_MISMATCH:
  1039. command_line.warn_mismatch = false;
  1040. break;
  1041. case OPTION_NO_WARN_SEARCH_MISMATCH:
  1042. command_line.warn_search_mismatch = false;
  1043. break;
  1044. case OPTION_NOINHIBIT_EXEC:
  1045. force_make_executable = true;
  1046. break;
  1047. case OPTION_NOSTDLIB:
  1048. config.only_cmd_line_lib_dirs = true;
  1049. break;
  1050. case OPTION_NO_WHOLE_ARCHIVE:
  1051. input_flags.whole_archive = false;
  1052. break;
  1053. case 'O':
  1054. /* FIXME "-O<non-digits> <value>" used to set the address of
  1055. section <non-digits>. Was this for compatibility with
  1056. something, or can we create a new option to do that
  1057. (with a syntax similar to -defsym)?
  1058. getopt can't handle two args to an option without kludges. */
  1059. /* Enable optimizations of output files. */
  1060. link_info.optimize = strtoul (optarg, NULL, 0) != 0;
  1061. break;
  1062. case 'o':
  1063. lang_add_output (optarg, 0);
  1064. break;
  1065. case OPTION_OFORMAT:
  1066. lang_add_output_format (optarg, NULL, NULL, 0);
  1067. break;
  1068. case OPTION_OUT_IMPLIB:
  1069. command_line.out_implib_filename = xstrdup (optarg);
  1070. break;
  1071. case OPTION_PRINT_SYSROOT:
  1072. if (*ld_sysroot)
  1073. puts (ld_sysroot);
  1074. xexit (0);
  1075. break;
  1076. case OPTION_PRINT_OUTPUT_FORMAT:
  1077. command_line.print_output_format = true;
  1078. break;
  1079. #if BFD_SUPPORTS_PLUGINS
  1080. case OPTION_PLUGIN:
  1081. plugin_opt_plugin (optarg);
  1082. break;
  1083. case OPTION_PLUGIN_OPT:
  1084. if (plugin_opt_plugin_arg (optarg))
  1085. einfo (_("%F%P: bad -plugin-opt option\n"));
  1086. break;
  1087. #endif /* BFD_SUPPORTS_PLUGINS */
  1088. case 'q':
  1089. link_info.emitrelocations = true;
  1090. break;
  1091. case 'i':
  1092. case 'r':
  1093. if (optind == last_optind)
  1094. /* This can happen if the user put "-rpath,a" on the command
  1095. line. (Or something similar. The comma is important).
  1096. Getopt becomes confused and thinks that this is a -r option
  1097. but it cannot parse the text after the -r so it refuses to
  1098. increment the optind counter. Detect this case and issue
  1099. an error message here. We cannot just make this a warning,
  1100. increment optind, and continue because getopt is too confused
  1101. and will seg-fault the next time around. */
  1102. einfo(_("%F%P: unrecognised option: %s\n"), argv[optind]);
  1103. if (bfd_link_pic (&link_info))
  1104. einfo (_("%F%P: -r and %s may not be used together\n"),
  1105. bfd_link_dll (&link_info) ? "-shared" : "-pie");
  1106. link_info.type = type_relocatable;
  1107. config.build_constructors = false;
  1108. config.magic_demand_paged = false;
  1109. config.text_read_only = false;
  1110. input_flags.dynamic = false;
  1111. break;
  1112. case 'R':
  1113. /* The GNU linker traditionally uses -R to mean to include
  1114. only the symbols from a file. The Solaris linker uses -R
  1115. to set the path used by the runtime linker to find
  1116. libraries. This is the GNU linker -rpath argument. We
  1117. try to support both simultaneously by checking the file
  1118. named. If it is a directory, rather than a regular file,
  1119. we assume -rpath was meant. */
  1120. {
  1121. struct stat s;
  1122. if (stat (optarg, &s) >= 0
  1123. && ! S_ISDIR (s.st_mode))
  1124. {
  1125. lang_add_input_file (optarg,
  1126. lang_input_file_is_symbols_only_enum,
  1127. NULL);
  1128. break;
  1129. }
  1130. }
  1131. /* Fall through. */
  1132. case OPTION_RPATH:
  1133. if (command_line.rpath == NULL)
  1134. command_line.rpath = xstrdup (optarg);
  1135. else
  1136. {
  1137. size_t rpath_len = strlen (command_line.rpath);
  1138. size_t optarg_len = strlen (optarg);
  1139. char *buf;
  1140. char *cp = command_line.rpath;
  1141. /* First see whether OPTARG is already in the path. */
  1142. do
  1143. {
  1144. if (strncmp (optarg, cp, optarg_len) == 0
  1145. && (cp[optarg_len] == 0
  1146. || cp[optarg_len] == config.rpath_separator))
  1147. /* We found it. */
  1148. break;
  1149. /* Not yet found. */
  1150. cp = strchr (cp, config.rpath_separator);
  1151. if (cp != NULL)
  1152. ++cp;
  1153. }
  1154. while (cp != NULL);
  1155. if (cp == NULL)
  1156. {
  1157. buf = (char *) xmalloc (rpath_len + optarg_len + 2);
  1158. sprintf (buf, "%s%c%s", command_line.rpath,
  1159. config.rpath_separator, optarg);
  1160. free (command_line.rpath);
  1161. command_line.rpath = buf;
  1162. }
  1163. }
  1164. break;
  1165. case OPTION_RPATH_LINK:
  1166. if (command_line.rpath_link == NULL)
  1167. command_line.rpath_link = xstrdup (optarg);
  1168. else
  1169. {
  1170. char *buf;
  1171. buf = (char *) xmalloc (strlen (command_line.rpath_link)
  1172. + strlen (optarg)
  1173. + 2);
  1174. sprintf (buf, "%s%c%s", command_line.rpath_link,
  1175. config.rpath_separator, optarg);
  1176. free (command_line.rpath_link);
  1177. command_line.rpath_link = buf;
  1178. }
  1179. break;
  1180. case OPTION_NO_RELAX:
  1181. DISABLE_RELAXATION;
  1182. break;
  1183. case OPTION_RELAX:
  1184. ENABLE_RELAXATION;
  1185. break;
  1186. case OPTION_RETAIN_SYMBOLS_FILE:
  1187. add_keepsyms_file (optarg);
  1188. break;
  1189. case 'S':
  1190. link_info.strip = strip_debugger;
  1191. break;
  1192. case 's':
  1193. link_info.strip = strip_all;
  1194. break;
  1195. case OPTION_STRIP_DISCARDED:
  1196. link_info.strip_discarded = true;
  1197. break;
  1198. case OPTION_NO_STRIP_DISCARDED:
  1199. link_info.strip_discarded = false;
  1200. break;
  1201. case OPTION_DISABLE_MULTIPLE_DEFS_ABS:
  1202. link_info.prohibit_multiple_definition_absolute = true;
  1203. break;
  1204. case OPTION_SHARED:
  1205. if (config.has_shared)
  1206. {
  1207. if (bfd_link_relocatable (&link_info))
  1208. einfo (_("%F%P: -r and %s may not be used together\n"),
  1209. "-shared");
  1210. link_info.type = type_dll;
  1211. /* When creating a shared library, the default
  1212. behaviour is to ignore any unresolved references. */
  1213. if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
  1214. link_info.unresolved_syms_in_objects = RM_IGNORE;
  1215. if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
  1216. link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
  1217. }
  1218. else
  1219. einfo (_("%F%P: -shared not supported\n"));
  1220. break;
  1221. case OPTION_NO_PIE:
  1222. link_info.type = type_pde;
  1223. break;
  1224. case OPTION_PIE:
  1225. if (config.has_shared)
  1226. {
  1227. if (bfd_link_relocatable (&link_info))
  1228. einfo (_("%F%P: -r and %s may not be used together\n"), "-pie");
  1229. link_info.type = type_pie;
  1230. }
  1231. else
  1232. einfo (_("%F%P: -pie not supported\n"));
  1233. break;
  1234. case 'h': /* Used on Solaris. */
  1235. case OPTION_SONAME:
  1236. if (optarg[0] == '\0' && command_line.soname
  1237. && command_line.soname[0])
  1238. einfo (_("%P: SONAME must not be empty string; keeping previous one\n"));
  1239. else
  1240. command_line.soname = optarg;
  1241. break;
  1242. case OPTION_SORT_COMMON:
  1243. if (optarg == NULL
  1244. || strcmp (optarg, N_("descending")) == 0)
  1245. config.sort_common = sort_descending;
  1246. else if (strcmp (optarg, N_("ascending")) == 0)
  1247. config.sort_common = sort_ascending;
  1248. else
  1249. einfo (_("%F%P: invalid common section sorting option: %s\n"),
  1250. optarg);
  1251. break;
  1252. case OPTION_SORT_SECTION:
  1253. if (strcmp (optarg, N_("name")) == 0)
  1254. sort_section = by_name;
  1255. else if (strcmp (optarg, N_("alignment")) == 0)
  1256. sort_section = by_alignment;
  1257. else
  1258. einfo (_("%F%P: invalid section sorting option: %s\n"),
  1259. optarg);
  1260. break;
  1261. case OPTION_STATS:
  1262. config.stats = true;
  1263. break;
  1264. case OPTION_NO_SYMBOLIC:
  1265. opt_symbolic = symbolic_unset;
  1266. break;
  1267. case OPTION_SYMBOLIC:
  1268. opt_symbolic = symbolic;
  1269. break;
  1270. case OPTION_SYMBOLIC_FUNCTIONS:
  1271. opt_symbolic = symbolic_functions;
  1272. break;
  1273. case 't':
  1274. ++trace_files;
  1275. break;
  1276. case 'T':
  1277. previous_script_handle = saved_script_handle;
  1278. ldfile_open_script_file (optarg);
  1279. parser_input = input_script;
  1280. yyparse ();
  1281. previous_script_handle = NULL;
  1282. break;
  1283. case OPTION_DEFAULT_SCRIPT:
  1284. command_line.default_script = optarg;
  1285. break;
  1286. case OPTION_SECTION_START:
  1287. {
  1288. char *optarg2;
  1289. char *sec_name;
  1290. int len;
  1291. /* Check for <something>=<somthing>... */
  1292. optarg2 = strchr (optarg, '=');
  1293. if (optarg2 == NULL)
  1294. einfo (_("%F%P: invalid argument to option"
  1295. " \"--section-start\"\n"));
  1296. optarg2++;
  1297. /* So far so good. Are all the args present? */
  1298. if ((*optarg == '\0') || (*optarg2 == '\0'))
  1299. einfo (_("%F%P: missing argument(s) to option"
  1300. " \"--section-start\"\n"));
  1301. /* We must copy the section name as set_section_start
  1302. doesn't do it for us. */
  1303. len = optarg2 - optarg;
  1304. sec_name = (char *) xmalloc (len);
  1305. memcpy (sec_name, optarg, len - 1);
  1306. sec_name[len - 1] = 0;
  1307. /* Then set it... */
  1308. set_section_start (sec_name, optarg2);
  1309. }
  1310. break;
  1311. case OPTION_TARGET_HELP:
  1312. /* Mention any target specific options. */
  1313. ldemul_list_emulation_options (stdout);
  1314. exit (0);
  1315. case OPTION_TBSS:
  1316. set_segment_start (".bss", optarg);
  1317. break;
  1318. case OPTION_TDATA:
  1319. set_segment_start (".data", optarg);
  1320. break;
  1321. case OPTION_TTEXT:
  1322. set_segment_start (".text", optarg);
  1323. break;
  1324. case OPTION_TTEXT_SEGMENT:
  1325. set_segment_start (".text-segment", optarg);
  1326. break;
  1327. case OPTION_TRODATA_SEGMENT:
  1328. set_segment_start (".rodata-segment", optarg);
  1329. break;
  1330. case OPTION_TLDATA_SEGMENT:
  1331. set_segment_start (".ldata-segment", optarg);
  1332. break;
  1333. case OPTION_TRADITIONAL_FORMAT:
  1334. link_info.traditional_format = true;
  1335. break;
  1336. case OPTION_TASK_LINK:
  1337. link_info.task_link = true;
  1338. /* Fall through. */
  1339. case OPTION_UR:
  1340. if (bfd_link_pic (&link_info))
  1341. einfo (_("%F%P: -r and %s may not be used together\n"),
  1342. bfd_link_dll (&link_info) ? "-shared" : "-pie");
  1343. link_info.type = type_relocatable;
  1344. config.build_constructors = true;
  1345. config.magic_demand_paged = false;
  1346. config.text_read_only = false;
  1347. input_flags.dynamic = false;
  1348. break;
  1349. case 'u':
  1350. ldlang_add_undef (optarg, true);
  1351. break;
  1352. case OPTION_REQUIRE_DEFINED_SYMBOL:
  1353. ldlang_add_require_defined (optarg);
  1354. break;
  1355. case OPTION_UNIQUE:
  1356. if (optarg != NULL)
  1357. lang_add_unique (optarg);
  1358. else
  1359. config.unique_orphan_sections = true;
  1360. break;
  1361. case OPTION_VERBOSE:
  1362. ldversion (1);
  1363. version_printed = true;
  1364. verbose = true;
  1365. overflow_cutoff_limit = -2;
  1366. if (optarg != NULL)
  1367. {
  1368. char *end;
  1369. int level ATTRIBUTE_UNUSED = strtoul (optarg, &end, 0);
  1370. if (*end)
  1371. einfo (_("%F%P: invalid number `%s'\n"), optarg);
  1372. #if BFD_SUPPORTS_PLUGINS
  1373. report_plugin_symbols = level > 1;
  1374. #endif /* BFD_SUPPORTS_PLUGINS */
  1375. }
  1376. break;
  1377. case 'v':
  1378. ldversion (0);
  1379. version_printed = true;
  1380. break;
  1381. case 'V':
  1382. ldversion (1);
  1383. version_printed = true;
  1384. break;
  1385. case OPTION_VERSION:
  1386. ldversion (2);
  1387. xexit (0);
  1388. break;
  1389. case OPTION_VERSION_SCRIPT:
  1390. /* This option indicates a small script that only specifies
  1391. version information. Read it, but don't assume that
  1392. we've seen a linker script. */
  1393. {
  1394. FILE *hold_script_handle;
  1395. hold_script_handle = saved_script_handle;
  1396. ldfile_open_command_file (optarg);
  1397. saved_script_handle = hold_script_handle;
  1398. parser_input = input_version_script;
  1399. yyparse ();
  1400. }
  1401. break;
  1402. case OPTION_VERSION_EXPORTS_SECTION:
  1403. /* This option records a version symbol to be applied to the
  1404. symbols listed for export to be found in the object files
  1405. .exports sections. */
  1406. command_line.version_exports_section = optarg;
  1407. break;
  1408. case OPTION_DYNAMIC_LIST_DATA:
  1409. opt_dynamic_list = dynamic_list_data;
  1410. break;
  1411. case OPTION_DYNAMIC_LIST_CPP_TYPEINFO:
  1412. lang_append_dynamic_list_cpp_typeinfo ();
  1413. if (opt_dynamic_list != dynamic_list_data)
  1414. opt_dynamic_list = dynamic_list;
  1415. break;
  1416. case OPTION_DYNAMIC_LIST_CPP_NEW:
  1417. lang_append_dynamic_list_cpp_new ();
  1418. if (opt_dynamic_list != dynamic_list_data)
  1419. opt_dynamic_list = dynamic_list;
  1420. break;
  1421. case OPTION_DYNAMIC_LIST:
  1422. /* This option indicates a small script that only specifies
  1423. a dynamic list. Read it, but don't assume that we've
  1424. seen a linker script. */
  1425. {
  1426. FILE *hold_script_handle;
  1427. hold_script_handle = saved_script_handle;
  1428. ldfile_open_command_file (optarg);
  1429. saved_script_handle = hold_script_handle;
  1430. parser_input = input_dynamic_list;
  1431. current_dynamic_list_p = &link_info.dynamic_list;
  1432. yyparse ();
  1433. }
  1434. if (opt_dynamic_list != dynamic_list_data)
  1435. opt_dynamic_list = dynamic_list;
  1436. break;
  1437. case OPTION_EXPORT_DYNAMIC_SYMBOL:
  1438. {
  1439. struct bfd_elf_version_expr *expr
  1440. = lang_new_vers_pattern (NULL, xstrdup (optarg), NULL,
  1441. false);
  1442. lang_append_dynamic_list (&export_list, expr);
  1443. }
  1444. break;
  1445. case OPTION_EXPORT_DYNAMIC_SYMBOL_LIST:
  1446. /* This option indicates a small script that only specifies
  1447. an export list. Read it, but don't assume that we've
  1448. seen a linker script. */
  1449. {
  1450. FILE *hold_script_handle;
  1451. hold_script_handle = saved_script_handle;
  1452. ldfile_open_command_file (optarg);
  1453. saved_script_handle = hold_script_handle;
  1454. parser_input = input_dynamic_list;
  1455. current_dynamic_list_p = &export_list;
  1456. yyparse ();
  1457. }
  1458. break;
  1459. case OPTION_WARN_COMMON:
  1460. config.warn_common = true;
  1461. break;
  1462. case OPTION_WARN_CONSTRUCTORS:
  1463. config.warn_constructors = true;
  1464. break;
  1465. case OPTION_WARN_FATAL:
  1466. config.fatal_warnings = true;
  1467. break;
  1468. case OPTION_NO_WARN_FATAL:
  1469. config.fatal_warnings = false;
  1470. break;
  1471. case OPTION_WARN_MULTIPLE_GP:
  1472. config.warn_multiple_gp = true;
  1473. break;
  1474. case OPTION_WARN_ONCE:
  1475. config.warn_once = true;
  1476. break;
  1477. case OPTION_WARN_SECTION_ALIGN:
  1478. config.warn_section_align = true;
  1479. break;
  1480. case OPTION_WARN_TEXTREL:
  1481. link_info.textrel_check = textrel_check_warning;
  1482. break;
  1483. case OPTION_WARN_ALTERNATE_EM:
  1484. link_info.warn_alternate_em = true;
  1485. break;
  1486. case OPTION_WHOLE_ARCHIVE:
  1487. input_flags.whole_archive = true;
  1488. break;
  1489. case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC:
  1490. input_flags.add_DT_NEEDED_for_dynamic = true;
  1491. break;
  1492. case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC:
  1493. input_flags.add_DT_NEEDED_for_dynamic = false;
  1494. break;
  1495. case OPTION_ADD_DT_NEEDED_FOR_REGULAR:
  1496. input_flags.add_DT_NEEDED_for_regular = true;
  1497. break;
  1498. case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR:
  1499. input_flags.add_DT_NEEDED_for_regular = false;
  1500. break;
  1501. case OPTION_WRAP:
  1502. add_wrap (optarg);
  1503. break;
  1504. case OPTION_IGNORE_UNRESOLVED_SYMBOL:
  1505. add_ignoresym (&link_info, optarg);
  1506. break;
  1507. case OPTION_DISCARD_NONE:
  1508. link_info.discard = discard_none;
  1509. break;
  1510. case 'X':
  1511. link_info.discard = discard_l;
  1512. break;
  1513. case 'x':
  1514. link_info.discard = discard_all;
  1515. break;
  1516. case 'Y':
  1517. if (startswith (optarg, "P,"))
  1518. optarg += 2;
  1519. free (default_dirlist);
  1520. default_dirlist = xstrdup (optarg);
  1521. break;
  1522. case 'y':
  1523. add_ysym (optarg);
  1524. break;
  1525. case OPTION_SPARE_DYNAMIC_TAGS:
  1526. link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
  1527. break;
  1528. case OPTION_SPLIT_BY_RELOC:
  1529. if (optarg != NULL)
  1530. config.split_by_reloc = strtoul (optarg, NULL, 0);
  1531. else
  1532. config.split_by_reloc = 32768;
  1533. break;
  1534. case OPTION_SPLIT_BY_FILE:
  1535. if (optarg != NULL)
  1536. config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
  1537. else
  1538. config.split_by_file = 1;
  1539. break;
  1540. case OPTION_CHECK_SECTIONS:
  1541. command_line.check_section_addresses = 1;
  1542. break;
  1543. case OPTION_NO_CHECK_SECTIONS:
  1544. command_line.check_section_addresses = 0;
  1545. break;
  1546. case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
  1547. command_line.accept_unknown_input_arch = true;
  1548. break;
  1549. case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
  1550. command_line.accept_unknown_input_arch = false;
  1551. break;
  1552. case '(':
  1553. lang_enter_group ();
  1554. ingroup++;
  1555. break;
  1556. case ')':
  1557. if (! ingroup)
  1558. einfo (_("%F%P: group ended before it began (--help for usage)\n"));
  1559. lang_leave_group ();
  1560. ingroup--;
  1561. break;
  1562. case OPTION_INIT:
  1563. link_info.init_function = optarg;
  1564. break;
  1565. case OPTION_FINI:
  1566. link_info.fini_function = optarg;
  1567. break;
  1568. case OPTION_REDUCE_MEMORY_OVERHEADS:
  1569. link_info.reduce_memory_overheads = true;
  1570. if (config.hash_table_size == 0)
  1571. config.hash_table_size = 1021;
  1572. break;
  1573. case OPTION_MAX_CACHE_SIZE:
  1574. {
  1575. char *end;
  1576. bfd_size_type cache_size = strtoul (optarg, &end, 0);
  1577. if (*end != '\0')
  1578. einfo (_("%F%P: invalid cache memory size: %s\n"),
  1579. optarg);
  1580. link_info.max_cache_size = cache_size;
  1581. }
  1582. break;
  1583. case OPTION_HASH_SIZE:
  1584. {
  1585. bfd_size_type new_size;
  1586. new_size = strtoul (optarg, NULL, 0);
  1587. if (new_size)
  1588. config.hash_table_size = new_size;
  1589. else
  1590. einfo (_("%X%P: --hash-size needs a numeric argument\n"));
  1591. }
  1592. break;
  1593. case OPTION_PUSH_STATE:
  1594. input_flags.pushed = xmemdup (&input_flags,
  1595. sizeof (input_flags),
  1596. sizeof (input_flags));
  1597. break;
  1598. case OPTION_POP_STATE:
  1599. if (input_flags.pushed == NULL)
  1600. einfo (_("%F%P: no state pushed before popping\n"));
  1601. else
  1602. {
  1603. struct lang_input_statement_flags *oldp = input_flags.pushed;
  1604. memcpy (&input_flags, oldp, sizeof (input_flags));
  1605. free (oldp);
  1606. }
  1607. break;
  1608. case OPTION_PRINT_MEMORY_USAGE:
  1609. command_line.print_memory_usage = true;
  1610. break;
  1611. case OPTION_ORPHAN_HANDLING:
  1612. if (strcasecmp (optarg, "place") == 0)
  1613. config.orphan_handling = orphan_handling_place;
  1614. else if (strcasecmp (optarg, "warn") == 0)
  1615. config.orphan_handling = orphan_handling_warn;
  1616. else if (strcasecmp (optarg, "error") == 0)
  1617. config.orphan_handling = orphan_handling_error;
  1618. else if (strcasecmp (optarg, "discard") == 0)
  1619. config.orphan_handling = orphan_handling_discard;
  1620. else
  1621. einfo (_("%F%P: invalid argument to option"
  1622. " \"--orphan-handling\"\n"));
  1623. break;
  1624. case OPTION_NO_PRINT_MAP_DISCARDED:
  1625. config.print_map_discarded = false;
  1626. break;
  1627. case OPTION_PRINT_MAP_DISCARDED:
  1628. config.print_map_discarded = true;
  1629. break;
  1630. case OPTION_DEPENDENCY_FILE:
  1631. config.dependency_file = optarg;
  1632. break;
  1633. case OPTION_CTF_VARIABLES:
  1634. config.ctf_variables = true;
  1635. break;
  1636. case OPTION_NO_CTF_VARIABLES:
  1637. config.ctf_variables = false;
  1638. break;
  1639. case OPTION_CTF_SHARE_TYPES:
  1640. if (strcmp (optarg, "share-unconflicted") == 0)
  1641. config.ctf_share_duplicated = false;
  1642. else if (strcmp (optarg, "share-duplicated") == 0)
  1643. config.ctf_share_duplicated = true;
  1644. else
  1645. einfo (_("%F%P: bad --ctf-share-types option: %s\n"), optarg);
  1646. break;
  1647. }
  1648. }
  1649. free (really_longopts);
  1650. free (longopts);
  1651. free (shortopts);
  1652. /* Run a couple of checks on the map filename. */
  1653. if (config.map_filename)
  1654. {
  1655. char * new_name = NULL;
  1656. char * percent;
  1657. int res = 0;
  1658. if (config.map_filename[0] == 0)
  1659. {
  1660. einfo (_("%P: no file/directory name provided for map output; ignored\n"));
  1661. config.map_filename = NULL;
  1662. }
  1663. else if (strcmp (config.map_filename, "-") == 0)
  1664. ; /* Write to stdout. Handled in main(). */
  1665. else if ((percent = strchr (config.map_filename, '%')) != NULL)
  1666. {
  1667. /* FIXME: Check for a second % character and issue an error ? */
  1668. /* Construct a map file by replacing the % character with the (full)
  1669. output filename. If the % character was the last character in
  1670. the original map filename then add a .map extension. */
  1671. percent[0] = 0;
  1672. res = asprintf (&new_name, "%s%s%s", config.map_filename,
  1673. output_filename,
  1674. percent[1] ? percent + 1 : ".map");
  1675. /* FIXME: Should we ensure that any directory components in new_name exist ? */
  1676. }
  1677. else
  1678. {
  1679. struct stat s;
  1680. /* If the map filename is actually a directory then create
  1681. a file inside it, based upon the output filename. */
  1682. if (stat (config.map_filename, &s) < 0)
  1683. {
  1684. if (errno != ENOENT)
  1685. einfo (_("%P: cannot stat linker map file: %E\n"));
  1686. }
  1687. else if (S_ISDIR (s.st_mode))
  1688. {
  1689. char lastc = config.map_filename[strlen (config.map_filename) - 1];
  1690. res = asprintf (&new_name, "%s%s%s.map",
  1691. config.map_filename,
  1692. IS_DIR_SEPARATOR (lastc) ? "" : "/",
  1693. lbasename (output_filename));
  1694. }
  1695. else if (! S_ISREG (s.st_mode))
  1696. {
  1697. einfo (_("%P: linker map file is not a regular file\n"));
  1698. config.map_filename = NULL;
  1699. }
  1700. /* else FIXME: Check write permission ? */
  1701. }
  1702. if (res < 0)
  1703. {
  1704. /* If the asprintf failed then something is probably very
  1705. wrong. Better to halt now rather than continue on
  1706. into more problems. */
  1707. einfo (_("%P%F: cannot create name for linker map file: %E\n"));
  1708. }
  1709. else if (new_name != NULL)
  1710. {
  1711. /* This is a trivial memory leak. */
  1712. config.map_filename = new_name;
  1713. }
  1714. }
  1715. if (command_line.soname && command_line.soname[0] == '\0')
  1716. {
  1717. einfo (_("%P: SONAME must not be empty string; ignored\n"));
  1718. command_line.soname = NULL;
  1719. }
  1720. while (ingroup)
  1721. {
  1722. einfo (_("%P: missing --end-group; added as last command line option\n"));
  1723. lang_leave_group ();
  1724. ingroup--;
  1725. }
  1726. if (default_dirlist != NULL)
  1727. {
  1728. set_default_dirlist (default_dirlist);
  1729. free (default_dirlist);
  1730. }
  1731. if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
  1732. /* FIXME: Should we allow emulations a chance to set this ? */
  1733. link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
  1734. if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
  1735. /* FIXME: Should we allow emulations a chance to set this ? */
  1736. link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
  1737. if (bfd_link_relocatable (&link_info)
  1738. && command_line.check_section_addresses < 0)
  1739. command_line.check_section_addresses = 0;
  1740. if (export_list)
  1741. {
  1742. struct bfd_elf_version_expr *head = export_list->head.list;
  1743. struct bfd_elf_version_expr *next;
  1744. /* For --export-dynamic-symbol[-list]:
  1745. 1. When building executable, treat like --dynamic-list.
  1746. 2. When building shared object:
  1747. a. If -Bsymbolic or --dynamic-list are used, treat like
  1748. --dynamic-list.
  1749. b. Otherwise, ignored.
  1750. */
  1751. if (!bfd_link_relocatable (&link_info)
  1752. && (bfd_link_executable (&link_info)
  1753. || opt_symbolic != symbolic_unset
  1754. || opt_dynamic_list != dynamic_list_unset))
  1755. {
  1756. /* Append the export list to link_info.dynamic_list. */
  1757. if (link_info.dynamic_list)
  1758. {
  1759. for (next = head; next->next != NULL; next = next->next)
  1760. ;
  1761. next->next = link_info.dynamic_list->head.list;
  1762. link_info.dynamic_list->head.list = head;
  1763. }
  1764. else
  1765. link_info.dynamic_list = export_list;
  1766. if (opt_dynamic_list != dynamic_list_data)
  1767. opt_dynamic_list = dynamic_list;
  1768. }
  1769. else
  1770. {
  1771. /* Free the export list. */
  1772. for (; head->next != NULL; head = next)
  1773. {
  1774. next = head->next;
  1775. free (head);
  1776. }
  1777. free (export_list);
  1778. }
  1779. }
  1780. switch (opt_dynamic_list)
  1781. {
  1782. case dynamic_list_unset:
  1783. break;
  1784. case dynamic_list_data:
  1785. link_info.dynamic_data = true;
  1786. /* Fall through. */
  1787. case dynamic_list:
  1788. link_info.dynamic = true;
  1789. opt_symbolic = symbolic_unset;
  1790. break;
  1791. }
  1792. /* -Bsymbolic and -Bsymbols-functions are for shared library output. */
  1793. if (bfd_link_dll (&link_info))
  1794. switch (opt_symbolic)
  1795. {
  1796. case symbolic_unset:
  1797. break;
  1798. case symbolic:
  1799. link_info.symbolic = true;
  1800. if (link_info.dynamic_list)
  1801. {
  1802. struct bfd_elf_version_expr *ent, *next;
  1803. for (ent = link_info.dynamic_list->head.list; ent; ent = next)
  1804. {
  1805. next = ent->next;
  1806. free (ent);
  1807. }
  1808. free (link_info.dynamic_list);
  1809. link_info.dynamic_list = NULL;
  1810. }
  1811. break;
  1812. case symbolic_functions:
  1813. link_info.dynamic = true;
  1814. link_info.dynamic_data = true;
  1815. break;
  1816. }
  1817. if (!bfd_link_dll (&link_info))
  1818. {
  1819. if (command_line.filter_shlib)
  1820. einfo (_("%F%P: -F may not be used without -shared\n"));
  1821. if (command_line.auxiliary_filters)
  1822. einfo (_("%F%P: -f may not be used without -shared\n"));
  1823. }
  1824. /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
  1825. don't see how else this can be handled, since in this case we
  1826. must preserve all externally visible symbols. */
  1827. if (bfd_link_relocatable (&link_info) && link_info.strip == strip_all)
  1828. {
  1829. link_info.strip = strip_debugger;
  1830. if (link_info.discard == discard_sec_merge)
  1831. link_info.discard = discard_all;
  1832. }
  1833. }
  1834. /* Add the (colon-separated) elements of DIRLIST_PTR to the
  1835. library search path. */
  1836. static void
  1837. set_default_dirlist (char *dirlist_ptr)
  1838. {
  1839. char *p;
  1840. while (1)
  1841. {
  1842. p = strchr (dirlist_ptr, PATH_SEPARATOR);
  1843. if (p != NULL)
  1844. *p = '\0';
  1845. if (*dirlist_ptr != '\0')
  1846. ldfile_add_library_path (dirlist_ptr, true);
  1847. if (p == NULL)
  1848. break;
  1849. dirlist_ptr = p + 1;
  1850. }
  1851. }
  1852. static void
  1853. set_section_start (char *sect, char *valstr)
  1854. {
  1855. const char *end;
  1856. bfd_vma val = bfd_scan_vma (valstr, &end, 16);
  1857. if (*end)
  1858. einfo (_("%F%P: invalid hex number `%s'\n"), valstr);
  1859. lang_section_start (sect, exp_intop (val), NULL);
  1860. }
  1861. static void
  1862. set_segment_start (const char *section, char *valstr)
  1863. {
  1864. const char *name;
  1865. const char *end;
  1866. segment_type *seg;
  1867. bfd_vma val = bfd_scan_vma (valstr, &end, 16);
  1868. if (*end)
  1869. einfo (_("%F%P: invalid hex number `%s'\n"), valstr);
  1870. /* If we already have an entry for this segment, update the existing
  1871. value. */
  1872. name = section + 1;
  1873. for (seg = segments; seg; seg = seg->next)
  1874. if (strcmp (seg->name, name) == 0)
  1875. {
  1876. seg->value = val;
  1877. lang_section_start (section, exp_intop (val), seg);
  1878. return;
  1879. }
  1880. /* There was no existing value so we must create a new segment
  1881. entry. */
  1882. seg = stat_alloc (sizeof (*seg));
  1883. seg->name = name;
  1884. seg->value = val;
  1885. seg->used = false;
  1886. /* Add it to the linked list of segments. */
  1887. seg->next = segments;
  1888. segments = seg;
  1889. /* Historically, -Ttext and friends set the base address of a
  1890. particular section. For backwards compatibility, we still do
  1891. that. If a SEGMENT_START directive is seen, the section address
  1892. assignment will be disabled. */
  1893. lang_section_start (section, exp_intop (val), seg);
  1894. }
  1895. static void
  1896. elf_shlib_list_options (FILE *file)
  1897. {
  1898. fprintf (file, _("\
  1899. --audit=AUDITLIB Specify a library to use for auditing\n"));
  1900. fprintf (file, _("\
  1901. -Bgroup Selects group name lookup rules for DSO\n"));
  1902. fprintf (file, _("\
  1903. --disable-new-dtags Disable new dynamic tags\n"));
  1904. fprintf (file, _("\
  1905. --enable-new-dtags Enable new dynamic tags\n"));
  1906. fprintf (file, _("\
  1907. --eh-frame-hdr Create .eh_frame_hdr section\n"));
  1908. fprintf (file, _("\
  1909. --no-eh-frame-hdr Do not create .eh_frame_hdr section\n"));
  1910. fprintf (file, _("\
  1911. --exclude-libs=LIBS Make all symbols in LIBS hidden\n"));
  1912. fprintf (file, _("\
  1913. --hash-style=STYLE Set hash style to sysv/gnu/both. Default: "));
  1914. if (DEFAULT_EMIT_SYSV_HASH)
  1915. {
  1916. /* Note - these strings are not translated as
  1917. they are keywords not descriptive text. */
  1918. if (DEFAULT_EMIT_GNU_HASH)
  1919. fprintf (file, "both\n");
  1920. else
  1921. fprintf (file, "sysv\n");
  1922. }
  1923. else
  1924. {
  1925. if (DEFAULT_EMIT_GNU_HASH)
  1926. fprintf (file, "gnu\n");
  1927. else
  1928. /* FIXME: Can this happen ? */
  1929. fprintf (file, "none\n");
  1930. }
  1931. fprintf (file, _("\
  1932. -P AUDITLIB, --depaudit=AUDITLIB\n" "\
  1933. Specify a library to use for auditing dependencies\n"));
  1934. fprintf (file, _("\
  1935. -z combreloc Merge dynamic relocs into one section and sort\n"));
  1936. fprintf (file, _("\
  1937. -z nocombreloc Don't merge dynamic relocs into one section\n"));
  1938. fprintf (file, _("\
  1939. -z global Make symbols in DSO available for subsequently\n\
  1940. loaded objects\n"));
  1941. fprintf (file, _("\
  1942. -z initfirst Mark DSO to be initialized first at runtime\n"));
  1943. fprintf (file, _("\
  1944. -z interpose Mark object to interpose all DSOs but executable\n"));
  1945. fprintf (file, _("\
  1946. -z unique Mark DSO to be loaded at most once by default, and only in the main namespace\n"));
  1947. fprintf (file, _("\
  1948. -z nounique Don't mark DSO as a loadable at most once\n"));
  1949. fprintf (file, _("\
  1950. -z lazy Mark object lazy runtime binding (default)\n"));
  1951. fprintf (file, _("\
  1952. -z loadfltr Mark object requiring immediate process\n"));
  1953. fprintf (file, _("\
  1954. -z nocopyreloc Don't create copy relocs\n"));
  1955. fprintf (file, _("\
  1956. -z nodefaultlib Mark object not to use default search paths\n"));
  1957. fprintf (file, _("\
  1958. -z nodelete Mark DSO non-deletable at runtime\n"));
  1959. fprintf (file, _("\
  1960. -z nodlopen Mark DSO not available to dlopen\n"));
  1961. fprintf (file, _("\
  1962. -z nodump Mark DSO not available to dldump\n"));
  1963. fprintf (file, _("\
  1964. -z now Mark object non-lazy runtime binding\n"));
  1965. fprintf (file, _("\
  1966. -z origin Mark object requiring immediate $ORIGIN\n\
  1967. processing at runtime\n"));
  1968. #if DEFAULT_LD_Z_RELRO
  1969. fprintf (file, _("\
  1970. -z relro Create RELRO program header (default)\n"));
  1971. fprintf (file, _("\
  1972. -z norelro Don't create RELRO program header\n"));
  1973. #else
  1974. fprintf (file, _("\
  1975. -z relro Create RELRO program header\n"));
  1976. fprintf (file, _("\
  1977. -z norelro Don't create RELRO program header (default)\n"));
  1978. #endif
  1979. #if DEFAULT_LD_Z_SEPARATE_CODE
  1980. fprintf (file, _("\
  1981. -z separate-code Create separate code program header (default)\n"));
  1982. fprintf (file, _("\
  1983. -z noseparate-code Don't create separate code program header\n"));
  1984. #else
  1985. fprintf (file, _("\
  1986. -z separate-code Create separate code program header\n"));
  1987. fprintf (file, _("\
  1988. -z noseparate-code Don't create separate code program header (default)\n"));
  1989. #endif
  1990. fprintf (file, _("\
  1991. -z common Generate common symbols with STT_COMMON type\n"));
  1992. fprintf (file, _("\
  1993. -z nocommon Generate common symbols with STT_OBJECT type\n"));
  1994. if (link_info.textrel_check == textrel_check_error)
  1995. fprintf (file, _("\
  1996. -z text Treat DT_TEXTREL in output as error (default)\n"));
  1997. else
  1998. fprintf (file, _("\
  1999. -z text Treat DT_TEXTREL in output as error\n"));
  2000. if (link_info.textrel_check == textrel_check_none)
  2001. {
  2002. fprintf (file, _("\
  2003. -z notext Don't treat DT_TEXTREL in output as error (default)\n"));
  2004. fprintf (file, _("\
  2005. -z textoff Don't treat DT_TEXTREL in output as error (default)\n"));
  2006. }
  2007. else
  2008. {
  2009. fprintf (file, _("\
  2010. -z notext Don't treat DT_TEXTREL in output as error\n"));
  2011. fprintf (file, _("\
  2012. -z textoff Don't treat DT_TEXTREL in output as error\n"));
  2013. }
  2014. }
  2015. static void
  2016. elf_static_list_options (FILE *file)
  2017. {
  2018. fprintf (file, _("\
  2019. --build-id[=STYLE] Generate build ID note\n"));
  2020. fprintf (file, _("\
  2021. --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi]\n\
  2022. Compress DWARF debug sections using zlib\n"));
  2023. #ifdef DEFAULT_FLAG_COMPRESS_DEBUG
  2024. fprintf (file, _("\
  2025. Default: zlib-gabi\n"));
  2026. #else
  2027. fprintf (file, _("\
  2028. Default: none\n"));
  2029. #endif
  2030. fprintf (file, _("\
  2031. -z common-page-size=SIZE Set common page size to SIZE\n"));
  2032. fprintf (file, _("\
  2033. -z max-page-size=SIZE Set maximum page size to SIZE\n"));
  2034. fprintf (file, _("\
  2035. -z defs Report unresolved symbols in object files\n"));
  2036. fprintf (file, _("\
  2037. -z undefs Ignore unresolved symbols in object files\n"));
  2038. fprintf (file, _("\
  2039. -z muldefs Allow multiple definitions\n"));
  2040. fprintf (file, _("\
  2041. -z stack-size=SIZE Set size of stack segment\n"));
  2042. fprintf (file, _("\
  2043. -z execstack Mark executable as requiring executable stack\n"));
  2044. fprintf (file, _("\
  2045. -z noexecstack Mark executable as not requiring executable stack\n"));
  2046. fprintf (file, _("\
  2047. -z unique-symbol Avoid duplicated local symbol names\n"));
  2048. fprintf (file, _("\
  2049. -z nounique-symbol Keep duplicated local symbol names (default)\n"));
  2050. fprintf (file, _("\
  2051. -z globalaudit Mark executable requiring global auditing\n"));
  2052. fprintf (file, _("\
  2053. -z start-stop-gc Enable garbage collection on __start/__stop\n"));
  2054. fprintf (file, _("\
  2055. -z nostart-stop-gc Don't garbage collect __start/__stop (default)\n"));
  2056. fprintf (file, _("\
  2057. -z start-stop-visibility=V Set visibility of built-in __start/__stop symbols\n\
  2058. to DEFAULT, PROTECTED, HIDDEN or INTERNAL\n"));
  2059. }
  2060. static void
  2061. elf_plt_unwind_list_options (FILE *file)
  2062. {
  2063. fprintf (file, _("\
  2064. --ld-generated-unwind-info Generate exception handling info for PLT\n"));
  2065. fprintf (file, _("\
  2066. --no-ld-generated-unwind-info\n\
  2067. Don't generate exception handling info for PLT\n"));
  2068. }
  2069. static void
  2070. ld_list_options (FILE *file, bool elf, bool shlib, bool plt_unwind)
  2071. {
  2072. if (!elf)
  2073. return;
  2074. printf (_("ELF emulations:\n"));
  2075. if (plt_unwind)
  2076. elf_plt_unwind_list_options (file);
  2077. elf_static_list_options (file);
  2078. if (shlib)
  2079. elf_shlib_list_options (file);
  2080. }
  2081. /* Print help messages for the options. */
  2082. static void
  2083. help (void)
  2084. {
  2085. unsigned i;
  2086. const char **targets, **pp;
  2087. int len;
  2088. printf (_("Usage: %s [options] file...\n"), program_name);
  2089. printf (_("Options:\n"));
  2090. for (i = 0; i < OPTION_COUNT; i++)
  2091. {
  2092. if (ld_options[i].doc != NULL)
  2093. {
  2094. bool comma;
  2095. unsigned j;
  2096. printf (" ");
  2097. comma = false;
  2098. len = 2;
  2099. j = i;
  2100. do
  2101. {
  2102. if (ld_options[j].shortopt != '\0'
  2103. && ld_options[j].control != NO_HELP)
  2104. {
  2105. printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
  2106. len += (comma ? 2 : 0) + 2;
  2107. if (ld_options[j].arg != NULL)
  2108. {
  2109. if (ld_options[j].opt.has_arg != optional_argument)
  2110. {
  2111. printf (" ");
  2112. ++len;
  2113. }
  2114. printf ("%s", _(ld_options[j].arg));
  2115. len += strlen (_(ld_options[j].arg));
  2116. }
  2117. comma = true;
  2118. }
  2119. ++j;
  2120. }
  2121. while (j < OPTION_COUNT && ld_options[j].doc == NULL);
  2122. j = i;
  2123. do
  2124. {
  2125. if (ld_options[j].opt.name != NULL
  2126. && ld_options[j].control != NO_HELP)
  2127. {
  2128. int two_dashes =
  2129. (ld_options[j].control == TWO_DASHES
  2130. || ld_options[j].control == EXACTLY_TWO_DASHES);
  2131. printf ("%s-%s%s",
  2132. comma ? ", " : "",
  2133. two_dashes ? "-" : "",
  2134. ld_options[j].opt.name);
  2135. len += ((comma ? 2 : 0)
  2136. + 1
  2137. + (two_dashes ? 1 : 0)
  2138. + strlen (ld_options[j].opt.name));
  2139. if (ld_options[j].arg != NULL)
  2140. {
  2141. printf (" %s", _(ld_options[j].arg));
  2142. len += 1 + strlen (_(ld_options[j].arg));
  2143. }
  2144. comma = true;
  2145. }
  2146. ++j;
  2147. }
  2148. while (j < OPTION_COUNT && ld_options[j].doc == NULL);
  2149. if (len >= 30)
  2150. {
  2151. printf ("\n");
  2152. len = 0;
  2153. }
  2154. for (; len < 30; len++)
  2155. putchar (' ');
  2156. printf ("%s\n", _(ld_options[i].doc));
  2157. }
  2158. }
  2159. printf (_(" @FILE"));
  2160. for (len = strlen (" @FILE"); len < 30; len++)
  2161. putchar (' ');
  2162. printf (_("Read options from FILE\n"));
  2163. /* Note: Various tools (such as libtool) depend upon the
  2164. format of the listings below - do not change them. */
  2165. /* xgettext:c-format */
  2166. printf (_("%s: supported targets:"), program_name);
  2167. targets = bfd_target_list ();
  2168. for (pp = targets; *pp != NULL; pp++)
  2169. printf (" %s", *pp);
  2170. free (targets);
  2171. printf ("\n");
  2172. /* xgettext:c-format */
  2173. printf (_("%s: supported emulations: "), program_name);
  2174. ldemul_list_emulations (stdout);
  2175. printf ("\n");
  2176. /* xgettext:c-format */
  2177. printf (_("%s: emulation specific options:\n"), program_name);
  2178. ld_list_options (stdout, ELF_LIST_OPTIONS, ELF_SHLIB_LIST_OPTIONS,
  2179. ELF_PLT_UNWIND_LIST_OPTIONS);
  2180. ldemul_list_emulation_options (stdout);
  2181. printf ("\n");
  2182. if (REPORT_BUGS_TO[0])
  2183. printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);
  2184. }