lexsup.c 65 KB

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