options.h 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454
  1. // options.h -- handle command line options for gold -*- C++ -*-
  2. // Copyright (C) 2006-2022 Free Software Foundation, Inc.
  3. // Written by Ian Lance Taylor <iant@google.com>.
  4. // This file is part of gold.
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. // MA 02110-1301, USA.
  17. // General_options (from Command_line::options())
  18. // All the options (a.k.a. command-line flags)
  19. // Input_argument (from Command_line::inputs())
  20. // The list of input files, including -l options.
  21. // Command_line
  22. // Everything we get from the command line -- the General_options
  23. // plus the Input_arguments.
  24. //
  25. // There are also some smaller classes, such as
  26. // Position_dependent_options which hold a subset of General_options
  27. // that change as options are parsed (as opposed to the usual behavior
  28. // of the last instance of that option specified on the commandline wins).
  29. #ifndef GOLD_OPTIONS_H
  30. #define GOLD_OPTIONS_H
  31. #include <cstdlib>
  32. #include <cstring>
  33. #include <list>
  34. #include <map>
  35. #include <string>
  36. #include <vector>
  37. #include "elfcpp.h"
  38. #include "script.h"
  39. namespace gold
  40. {
  41. class Command_line;
  42. class General_options;
  43. class Search_directory;
  44. class Input_file_group;
  45. class Input_file_lib;
  46. class Position_dependent_options;
  47. class Target;
  48. class Plugin_manager;
  49. class Script_info;
  50. // Incremental build action for a specific file, as selected by the user.
  51. enum Incremental_disposition
  52. {
  53. // Startup files that appear before the first disposition option.
  54. // These will default to INCREMENTAL_CHECK unless the
  55. // --incremental-startup-unchanged option is given.
  56. // (For files added implicitly by gcc before any user options.)
  57. INCREMENTAL_STARTUP,
  58. // Determine the status from the timestamp (default).
  59. INCREMENTAL_CHECK,
  60. // Assume the file changed from the previous build.
  61. INCREMENTAL_CHANGED,
  62. // Assume the file didn't change from the previous build.
  63. INCREMENTAL_UNCHANGED
  64. };
  65. // The nested namespace is to contain all the global variables and
  66. // structs that need to be defined in the .h file, but do not need to
  67. // be used outside this class.
  68. namespace options
  69. {
  70. typedef std::vector<Search_directory> Dir_list;
  71. typedef Unordered_set<std::string> String_set;
  72. // These routines convert from a string option to various types.
  73. // Each gives a fatal error if it cannot parse the argument.
  74. extern void
  75. parse_bool(const char* option_name, const char* arg, bool* retval);
  76. extern void
  77. parse_int(const char* option_name, const char* arg, int* retval);
  78. extern void
  79. parse_uint(const char* option_name, const char* arg, int* retval);
  80. extern void
  81. parse_uint64(const char* option_name, const char* arg, uint64_t* retval);
  82. extern void
  83. parse_double(const char* option_name, const char* arg, double* retval);
  84. extern void
  85. parse_percent(const char* option_name, const char* arg, double* retval);
  86. extern void
  87. parse_string(const char* option_name, const char* arg, const char** retval);
  88. extern void
  89. parse_optional_string(const char* option_name, const char* arg,
  90. const char** retval);
  91. extern void
  92. parse_dirlist(const char* option_name, const char* arg, Dir_list* retval);
  93. extern void
  94. parse_set(const char* option_name, const char* arg, String_set* retval);
  95. extern void
  96. parse_choices(const char* option_name, const char* arg, const char** retval,
  97. const char* choices[], int num_choices);
  98. struct Struct_var;
  99. // Most options have both a shortname (one letter) and a longname.
  100. // This enum controls how many dashes are expected for longname access
  101. // -- shortnames always use one dash. Most longnames will accept
  102. // either one dash or two; the only difference between ONE_DASH and
  103. // TWO_DASHES is how we print the option in --help. However, some
  104. // longnames require two dashes, and some require only one. The
  105. // special value DASH_Z means that the option is preceded by "-z".
  106. enum Dashes
  107. {
  108. ONE_DASH, TWO_DASHES, EXACTLY_ONE_DASH, EXACTLY_TWO_DASHES, DASH_Z
  109. };
  110. // LONGNAME is the long-name of the option with dashes converted to
  111. // underscores, or else the short-name if the option has no long-name.
  112. // It is never the empty string.
  113. // DASHES is an instance of the Dashes enum: ONE_DASH, TWO_DASHES, etc.
  114. // SHORTNAME is the short-name of the option, as a char, or '\0' if the
  115. // option has no short-name. If the option has no long-name, you
  116. // should specify the short-name in *both* VARNAME and here.
  117. // DEFAULT_VALUE is the value of the option if not specified on the
  118. // commandline, as a string.
  119. // HELPSTRING is the descriptive text used with the option via --help
  120. // HELPARG is how you define the argument to the option.
  121. // --help output is "-shortname HELPARG, --longname HELPARG: HELPSTRING"
  122. // HELPARG should be NULL iff the option is a bool and takes no arg.
  123. // OPTIONAL_ARG is true if this option takes an optional argument. An
  124. // optional argument must be specifid as --OPTION=VALUE, not
  125. // --OPTION VALUE.
  126. // READER provides parse_to_value, which is a function that will convert
  127. // a char* argument into the proper type and store it in some variable.
  128. // IS_DEFAULT is true for boolean options that are on by default,
  129. // and thus should have "(default)" printed with the helpstring.
  130. // A One_option struct initializes itself with the global list of options
  131. // at constructor time, so be careful making one of these.
  132. struct One_option
  133. {
  134. std::string longname;
  135. Dashes dashes;
  136. char shortname;
  137. const char* default_value;
  138. const char* helpstring;
  139. const char* helparg;
  140. bool optional_arg;
  141. Struct_var* reader;
  142. bool is_default;
  143. One_option(const char* ln, Dashes d, char sn, const char* dv,
  144. const char* hs, const char* ha, bool oa, Struct_var* r,
  145. bool id)
  146. : longname(ln), dashes(d), shortname(sn), default_value(dv ? dv : ""),
  147. helpstring(hs), helparg(ha), optional_arg(oa), reader(r),
  148. is_default(id)
  149. {
  150. // In longname, we convert all underscores to dashes, since GNU
  151. // style uses dashes in option names. longname is likely to have
  152. // underscores in it because it's also used to declare a C++
  153. // function.
  154. const char* pos = strchr(this->longname.c_str(), '_');
  155. for (; pos; pos = strchr(pos, '_'))
  156. this->longname[pos - this->longname.c_str()] = '-';
  157. // We only register ourselves if our helpstring is not NULL. This
  158. // is to support the "no-VAR" boolean variables, which we
  159. // conditionally turn on by defining "no-VAR" help text.
  160. if (this->helpstring)
  161. this->register_option();
  162. }
  163. // This option takes an argument iff helparg is not NULL.
  164. bool
  165. takes_argument() const
  166. { return this->helparg != NULL; }
  167. // Whether the argument is optional.
  168. bool
  169. takes_optional_argument() const
  170. { return this->optional_arg; }
  171. // Register this option with the global list of options.
  172. void
  173. register_option();
  174. // Print this option to stdout (used with --help).
  175. void
  176. print() const;
  177. };
  178. // All options have a Struct_##varname that inherits from this and
  179. // actually implements parse_to_value for that option.
  180. struct Struct_var
  181. {
  182. // OPTION: the name of the option as specified on the commandline,
  183. // including leading dashes, and any text following the option:
  184. // "-O", "--defsym=mysym=0x1000", etc.
  185. // ARG: the arg associated with this option, or NULL if the option
  186. // takes no argument: "2", "mysym=0x1000", etc.
  187. // CMDLINE: the global Command_line object. Used by DEFINE_special.
  188. // OPTIONS: the global General_options object. Used by DEFINE_special.
  189. virtual void
  190. parse_to_value(const char* option, const char* arg,
  191. Command_line* cmdline, General_options* options) = 0;
  192. virtual
  193. ~Struct_var() // To make gcc happy.
  194. { }
  195. };
  196. // This is for "special" options that aren't of any predefined type.
  197. struct Struct_special : public Struct_var
  198. {
  199. // If you change this, change the parse-fn in DEFINE_special as well.
  200. typedef void (General_options::*Parse_function)(const char*, const char*,
  201. Command_line*);
  202. Struct_special(const char* varname, Dashes dashes, char shortname,
  203. Parse_function parse_function,
  204. const char* helpstring, const char* helparg)
  205. : option(varname, dashes, shortname, "", helpstring, helparg, false, this,
  206. false),
  207. parse(parse_function)
  208. { }
  209. void parse_to_value(const char* option, const char* arg,
  210. Command_line* cmdline, General_options* options)
  211. { (options->*(this->parse))(option, arg, cmdline); }
  212. One_option option;
  213. Parse_function parse;
  214. };
  215. } // End namespace options.
  216. // These are helper macros use by DEFINE_uint64/etc below.
  217. // This macro is used inside the General_options_ class, so defines
  218. // var() and set_var() as General_options methods. Arguments as are
  219. // for the constructor for One_option. param_type__ is the same as
  220. // type__ for built-in types, and "const type__ &" otherwise.
  221. //
  222. // When we define the linker command option "assert", the macro argument
  223. // varname__ of DEFINE_var below will be replaced by "assert". On Mac OSX
  224. // assert.h is included implicitly by one of the library headers we use. To
  225. // avoid unintended macro substitution of "assert()", we need to enclose
  226. // varname__ with parenthese.
  227. #define DEFINE_var(varname__, dashes__, shortname__, default_value__, \
  228. default_value_as_string__, helpstring__, helparg__, \
  229. optional_arg__, type__, param_type__, parse_fn__, \
  230. is_default__) \
  231. public: \
  232. param_type__ \
  233. (varname__)() const \
  234. { return this->varname__##_.value; } \
  235. \
  236. bool \
  237. user_set_##varname__() const \
  238. { return this->varname__##_.user_set_via_option; } \
  239. \
  240. void \
  241. set_user_set_##varname__() \
  242. { this->varname__##_.user_set_via_option = true; } \
  243. \
  244. static const bool varname__##is_default = is_default__; \
  245. \
  246. private: \
  247. struct Struct_##varname__ : public options::Struct_var \
  248. { \
  249. Struct_##varname__() \
  250. : option(#varname__, dashes__, shortname__, default_value_as_string__, \
  251. helpstring__, helparg__, optional_arg__, this, is_default__), \
  252. user_set_via_option(false), value(default_value__) \
  253. { } \
  254. \
  255. void \
  256. parse_to_value(const char* option_name, const char* arg, \
  257. Command_line*, General_options*) \
  258. { \
  259. parse_fn__(option_name, arg, &this->value); \
  260. this->user_set_via_option = true; \
  261. } \
  262. \
  263. options::One_option option; \
  264. bool user_set_via_option; \
  265. type__ value; \
  266. }; \
  267. Struct_##varname__ varname__##_; \
  268. void \
  269. set_##varname__(param_type__ value) \
  270. { this->varname__##_.value = value; }
  271. // These macros allow for easy addition of a new commandline option.
  272. // If no_helpstring__ is not NULL, then in addition to creating
  273. // VARNAME, we also create an option called no-VARNAME (or, for a -z
  274. // option, noVARNAME).
  275. #define DEFINE_bool(varname__, dashes__, shortname__, default_value__, \
  276. helpstring__, no_helpstring__) \
  277. DEFINE_var(varname__, dashes__, shortname__, default_value__, \
  278. default_value__ ? "true" : "false", helpstring__, NULL, \
  279. false, bool, bool, options::parse_bool, default_value__) \
  280. struct Struct_no_##varname__ : public options::Struct_var \
  281. { \
  282. Struct_no_##varname__() : option((dashes__ == options::DASH_Z \
  283. ? "no" #varname__ \
  284. : "no-" #varname__), \
  285. dashes__, '\0', \
  286. default_value__ ? "false" : "true", \
  287. no_helpstring__, NULL, false, this, \
  288. !(default_value__)) \
  289. { } \
  290. \
  291. void \
  292. parse_to_value(const char*, const char*, \
  293. Command_line*, General_options* options) \
  294. { \
  295. options->set_##varname__(false); \
  296. options->set_user_set_##varname__(); \
  297. } \
  298. \
  299. options::One_option option; \
  300. }; \
  301. Struct_no_##varname__ no_##varname__##_initializer_
  302. #define DEFINE_bool_ignore(varname__, dashes__, shortname__, \
  303. helpstring__, no_helpstring__) \
  304. DEFINE_var(varname__, dashes__, shortname__, false, \
  305. "false", helpstring__, NULL, \
  306. false, bool, bool, options::parse_bool, false) \
  307. struct Struct_no_##varname__ : public options::Struct_var \
  308. { \
  309. Struct_no_##varname__() : option((dashes__ == options::DASH_Z \
  310. ? "no" #varname__ \
  311. : "no-" #varname__), \
  312. dashes__, '\0', \
  313. "false", \
  314. no_helpstring__, NULL, false, this, \
  315. false) \
  316. { } \
  317. \
  318. void \
  319. parse_to_value(const char*, const char*, \
  320. Command_line*, General_options* options) \
  321. { \
  322. options->set_##varname__(false); \
  323. options->set_user_set_##varname__(); \
  324. } \
  325. \
  326. options::One_option option; \
  327. }; \
  328. Struct_no_##varname__ no_##varname__##_initializer_
  329. #define DEFINE_enable(varname__, dashes__, shortname__, default_value__, \
  330. helpstring__, no_helpstring__) \
  331. DEFINE_var(enable_##varname__, dashes__, shortname__, default_value__, \
  332. default_value__ ? "true" : "false", helpstring__, NULL, \
  333. false, bool, bool, options::parse_bool, default_value__) \
  334. struct Struct_disable_##varname__ : public options::Struct_var \
  335. { \
  336. Struct_disable_##varname__() : option("disable-" #varname__, \
  337. dashes__, '\0', \
  338. default_value__ ? "false" : "true", \
  339. no_helpstring__, NULL, false, this, \
  340. !default_value__) \
  341. { } \
  342. \
  343. void \
  344. parse_to_value(const char*, const char*, \
  345. Command_line*, General_options* options) \
  346. { options->set_enable_##varname__(false); } \
  347. \
  348. options::One_option option; \
  349. }; \
  350. Struct_disable_##varname__ disable_##varname__##_initializer_
  351. #define DEFINE_int(varname__, dashes__, shortname__, default_value__, \
  352. helpstring__, helparg__) \
  353. DEFINE_var(varname__, dashes__, shortname__, default_value__, \
  354. #default_value__, helpstring__, helparg__, false, \
  355. int, int, options::parse_int, false)
  356. #define DEFINE_uint(varname__, dashes__, shortname__, default_value__, \
  357. helpstring__, helparg__) \
  358. DEFINE_var(varname__, dashes__, shortname__, default_value__, \
  359. #default_value__, helpstring__, helparg__, false, \
  360. int, int, options::parse_uint, false)
  361. #define DEFINE_uint64(varname__, dashes__, shortname__, default_value__, \
  362. helpstring__, helparg__) \
  363. DEFINE_var(varname__, dashes__, shortname__, default_value__, \
  364. #default_value__, helpstring__, helparg__, false, \
  365. uint64_t, uint64_t, options::parse_uint64, false)
  366. #define DEFINE_double(varname__, dashes__, shortname__, default_value__, \
  367. helpstring__, helparg__) \
  368. DEFINE_var(varname__, dashes__, shortname__, default_value__, \
  369. #default_value__, helpstring__, helparg__, false, \
  370. double, double, options::parse_double, false)
  371. #define DEFINE_percent(varname__, dashes__, shortname__, default_value__, \
  372. helpstring__, helparg__) \
  373. DEFINE_var(varname__, dashes__, shortname__, default_value__ / 100.0, \
  374. #default_value__, helpstring__, helparg__, false, \
  375. double, double, options::parse_percent, false)
  376. #define DEFINE_string(varname__, dashes__, shortname__, default_value__, \
  377. helpstring__, helparg__) \
  378. DEFINE_var(varname__, dashes__, shortname__, default_value__, \
  379. default_value__, helpstring__, helparg__, false, \
  380. const char*, const char*, options::parse_string, false)
  381. // This is like DEFINE_string, but we convert each occurrence to a
  382. // Search_directory and store it in a vector. Thus we also have the
  383. // add_to_VARNAME() method, to append to the vector.
  384. #define DEFINE_dirlist(varname__, dashes__, shortname__, \
  385. helpstring__, helparg__) \
  386. DEFINE_var(varname__, dashes__, shortname__, , \
  387. "", helpstring__, helparg__, false, options::Dir_list, \
  388. const options::Dir_list&, options::parse_dirlist, false) \
  389. void \
  390. add_to_##varname__(const char* new_value) \
  391. { options::parse_dirlist(NULL, new_value, &this->varname__##_.value); } \
  392. void \
  393. add_search_directory_to_##varname__(const Search_directory& dir) \
  394. { this->varname__##_.value.push_back(dir); }
  395. // This is like DEFINE_string, but we store a set of strings.
  396. #define DEFINE_set(varname__, dashes__, shortname__, \
  397. helpstring__, helparg__) \
  398. DEFINE_var(varname__, dashes__, shortname__, , \
  399. "", helpstring__, helparg__, false, options::String_set, \
  400. const options::String_set&, options::parse_set, false) \
  401. public: \
  402. bool \
  403. any_##varname__() const \
  404. { return !this->varname__##_.value.empty(); } \
  405. \
  406. bool \
  407. is_##varname__(const char* symbol) const \
  408. { \
  409. return (!this->varname__##_.value.empty() \
  410. && (this->varname__##_.value.find(std::string(symbol)) \
  411. != this->varname__##_.value.end())); \
  412. } \
  413. \
  414. options::String_set::const_iterator \
  415. varname__##_begin() const \
  416. { return this->varname__##_.value.begin(); } \
  417. \
  418. options::String_set::const_iterator \
  419. varname__##_end() const \
  420. { return this->varname__##_.value.end(); } \
  421. \
  422. options::String_set::size_type \
  423. varname__##_size() const \
  424. { return this->varname__##_.value.size(); } \
  425. // When you have a list of possible values (expressed as string)
  426. // After helparg__ should come an initializer list, like
  427. // {"foo", "bar", "baz"}
  428. #define DEFINE_enum(varname__, dashes__, shortname__, default_value__, \
  429. helpstring__, helparg__, optional_arg__, ...) \
  430. DEFINE_var(varname__, dashes__, shortname__, default_value__, \
  431. default_value__, helpstring__, helparg__, optional_arg__, \
  432. const char*, const char*, parse_choices_##varname__, false) \
  433. private: \
  434. static void parse_choices_##varname__(const char* option_name, \
  435. const char* arg, \
  436. const char** retval) { \
  437. const char* choices[] = __VA_ARGS__; \
  438. options::parse_choices(option_name, arg, retval, \
  439. choices, sizeof(choices) / sizeof(*choices)); \
  440. }
  441. // This is like DEFINE_bool, but VARNAME is the name of a different
  442. // option. This option becomes an alias for that one. INVERT is true
  443. // if this option is an inversion of the other one.
  444. #define DEFINE_bool_alias(option__, varname__, dashes__, shortname__, \
  445. helpstring__, no_helpstring__, invert__) \
  446. private: \
  447. struct Struct_##option__ : public options::Struct_var \
  448. { \
  449. Struct_##option__() \
  450. : option(#option__, dashes__, shortname__, "", helpstring__, \
  451. NULL, false, this, \
  452. General_options::varname__##is_default ^ invert__) \
  453. { } \
  454. \
  455. void \
  456. parse_to_value(const char*, const char*, \
  457. Command_line*, General_options* options) \
  458. { \
  459. options->set_##varname__(!invert__); \
  460. options->set_user_set_##varname__(); \
  461. } \
  462. \
  463. options::One_option option; \
  464. }; \
  465. Struct_##option__ option__##_; \
  466. \
  467. struct Struct_no_##option__ : public options::Struct_var \
  468. { \
  469. Struct_no_##option__() \
  470. : option((dashes__ == options::DASH_Z \
  471. ? "no" #option__ \
  472. : "no-" #option__), \
  473. dashes__, '\0', "", no_helpstring__, \
  474. NULL, false, this, \
  475. !General_options::varname__##is_default ^ invert__) \
  476. { } \
  477. \
  478. void \
  479. parse_to_value(const char*, const char*, \
  480. Command_line*, General_options* options) \
  481. { \
  482. options->set_##varname__(invert__); \
  483. options->set_user_set_##varname__(); \
  484. } \
  485. \
  486. options::One_option option; \
  487. }; \
  488. Struct_no_##option__ no_##option__##_initializer_
  489. // This is like DEFINE_uint64, but VARNAME is the name of a different
  490. // option. This option becomes an alias for that one.
  491. #define DEFINE_uint64_alias(option__, varname__, dashes__, shortname__, \
  492. helpstring__, helparg__) \
  493. private: \
  494. struct Struct_##option__ : public options::Struct_var \
  495. { \
  496. Struct_##option__() \
  497. : option(#option__, dashes__, shortname__, "", helpstring__, \
  498. helparg__, false, this, false) \
  499. { } \
  500. \
  501. void \
  502. parse_to_value(const char* option_name, const char* arg, \
  503. Command_line*, General_options* options) \
  504. { \
  505. uint64_t value; \
  506. options::parse_uint64(option_name, arg, &value); \
  507. options->set_##varname__(value); \
  508. options->set_user_set_##varname__(); \
  509. } \
  510. \
  511. options::One_option option; \
  512. }; \
  513. Struct_##option__ option__##_;
  514. // This is used for non-standard flags. It defines no functions; it
  515. // just calls General_options::parse_VARNAME whenever the flag is
  516. // seen. We declare parse_VARNAME as a static member of
  517. // General_options; you are responsible for defining it there.
  518. // helparg__ should be NULL iff this special-option is a boolean.
  519. #define DEFINE_special(varname__, dashes__, shortname__, \
  520. helpstring__, helparg__) \
  521. private: \
  522. void parse_##varname__(const char* option, const char* arg, \
  523. Command_line* inputs); \
  524. struct Struct_##varname__ : public options::Struct_special \
  525. { \
  526. Struct_##varname__() \
  527. : options::Struct_special(#varname__, dashes__, shortname__, \
  528. &General_options::parse_##varname__, \
  529. helpstring__, helparg__) \
  530. { } \
  531. }; \
  532. Struct_##varname__ varname__##_initializer_
  533. // An option that takes an optional string argument. If the option is
  534. // used with no argument, the value will be the default, and
  535. // user_set_via_option will be true.
  536. #define DEFINE_optional_string(varname__, dashes__, shortname__, \
  537. default_value__, \
  538. helpstring__, helparg__) \
  539. DEFINE_var(varname__, dashes__, shortname__, default_value__, \
  540. default_value__, helpstring__, helparg__, true, \
  541. const char*, const char*, options::parse_optional_string, \
  542. false)
  543. // A directory to search. For each directory we record whether it is
  544. // in the sysroot. We need to know this so that, if a linker script
  545. // is found within the sysroot, we will apply the sysroot to any files
  546. // named by that script.
  547. class Search_directory
  548. {
  549. public:
  550. // We need a default constructor because we put this in a
  551. // std::vector.
  552. Search_directory()
  553. : name_(), put_in_sysroot_(false), is_in_sysroot_(false)
  554. { }
  555. // This is the usual constructor.
  556. Search_directory(const std::string& name, bool put_in_sysroot)
  557. : name_(name), put_in_sysroot_(put_in_sysroot), is_in_sysroot_(false)
  558. {
  559. if (this->name_.empty())
  560. this->name_ = ".";
  561. }
  562. // This is called if we have a sysroot. The sysroot is prefixed to
  563. // any entries for which put_in_sysroot_ is true. is_in_sysroot_ is
  564. // set to true for any enries which are in the sysroot (this will
  565. // naturally include any entries for which put_in_sysroot_ is true).
  566. // SYSROOT is the sysroot, CANONICAL_SYSROOT is the result of
  567. // passing SYSROOT to lrealpath.
  568. void
  569. add_sysroot(const char* sysroot, const char* canonical_sysroot);
  570. // Get the directory name.
  571. const std::string&
  572. name() const
  573. { return this->name_; }
  574. // Return whether this directory is in the sysroot.
  575. bool
  576. is_in_sysroot() const
  577. { return this->is_in_sysroot_; }
  578. // Return whether this is considered a system directory.
  579. bool
  580. is_system_directory() const
  581. { return this->put_in_sysroot_ || this->is_in_sysroot_; }
  582. private:
  583. // The directory name.
  584. std::string name_;
  585. // True if the sysroot should be added as a prefix for this
  586. // directory (if there is a sysroot). This is true for system
  587. // directories that we search by default.
  588. bool put_in_sysroot_;
  589. // True if this directory is in the sysroot (if there is a sysroot).
  590. // This is true if there is a sysroot and either 1) put_in_sysroot_
  591. // is true, or 2) the directory happens to be in the sysroot based
  592. // on a pathname comparison.
  593. bool is_in_sysroot_;
  594. };
  595. class General_options
  596. {
  597. private:
  598. // NOTE: For every option that you add here, also consider if you
  599. // should add it to Position_dependent_options.
  600. DEFINE_special(help, options::TWO_DASHES, '\0',
  601. N_("Report usage information"), NULL);
  602. DEFINE_special(version, options::TWO_DASHES, 'v',
  603. N_("Report version information"), NULL);
  604. DEFINE_special(V, options::EXACTLY_ONE_DASH, '\0',
  605. N_("Report version and target information"), NULL);
  606. // These options are sorted approximately so that for each letter in
  607. // the alphabet, we show the option whose shortname is that letter
  608. // (if any) and then every longname that starts with that letter (in
  609. // alphabetical order). For both, lowercase sorts before uppercase.
  610. // The -z options come last.
  611. // a
  612. DEFINE_bool(add_needed, options::TWO_DASHES, '\0', false,
  613. N_("Not supported"),
  614. N_("Do not copy DT_NEEDED tags from shared libraries"));
  615. DEFINE_bool_alias(allow_multiple_definition, muldefs, options::TWO_DASHES,
  616. '\0',
  617. N_("Allow multiple definitions of symbols"),
  618. N_("Do not allow multiple definitions"), false);
  619. DEFINE_bool(allow_shlib_undefined, options::TWO_DASHES, '\0', false,
  620. N_("Allow unresolved references in shared libraries"),
  621. N_("Do not allow unresolved references in shared libraries"));
  622. DEFINE_bool(apply_dynamic_relocs, options::TWO_DASHES, '\0', true,
  623. N_("Apply link-time values for dynamic relocations"),
  624. N_("(aarch64 only) Do not apply link-time values "
  625. "for dynamic relocations"));
  626. DEFINE_bool(as_needed, options::TWO_DASHES, '\0', false,
  627. N_("Use DT_NEEDED only for shared libraries that are used"),
  628. N_("Use DT_NEEDED for all shared libraries"));
  629. DEFINE_enum(assert, options::ONE_DASH, '\0', NULL,
  630. N_("Ignored"), N_("[ignored]"), false,
  631. {"definitions", "nodefinitions", "nosymbolic", "pure-text"});
  632. // b
  633. // This should really be an "enum", but it's too easy for folks to
  634. // forget to update the list as they add new targets. So we just
  635. // accept any string. We'll fail later (when the string is parsed),
  636. // if the target isn't actually supported.
  637. DEFINE_string(format, options::TWO_DASHES, 'b', "elf",
  638. N_("Set input format"), ("[elf,binary]"));
  639. DEFINE_bool(be8, options::TWO_DASHES, '\0', false,
  640. N_("Output BE8 format image"), NULL);
  641. DEFINE_optional_string(build_id, options::TWO_DASHES, '\0', "tree",
  642. N_("Generate build ID note"),
  643. N_("[=STYLE]"));
  644. DEFINE_uint64(build_id_chunk_size_for_treehash,
  645. options::TWO_DASHES, '\0', 2 << 20,
  646. N_("Chunk size for '--build-id=tree'"), N_("SIZE"));
  647. DEFINE_uint64(build_id_min_file_size_for_treehash, options::TWO_DASHES,
  648. '\0', 40 << 20,
  649. N_("Minimum output file size for '--build-id=tree' to work"
  650. " differently than '--build-id=sha1'"), N_("SIZE"));
  651. DEFINE_bool(Bdynamic, options::ONE_DASH, '\0', true,
  652. N_("-l searches for shared libraries"), NULL);
  653. DEFINE_bool_alias(Bstatic, Bdynamic, options::ONE_DASH, '\0',
  654. N_("-l does not search for shared libraries"), NULL,
  655. true);
  656. DEFINE_bool_alias(dy, Bdynamic, options::ONE_DASH, '\0',
  657. N_("alias for -Bdynamic"), NULL, false);
  658. DEFINE_bool_alias(dn, Bdynamic, options::ONE_DASH, '\0',
  659. N_("alias for -Bstatic"), NULL, true);
  660. DEFINE_bool(Bgroup, options::ONE_DASH, '\0', false,
  661. N_("Use group name lookup rules for shared library"), NULL);
  662. DEFINE_bool(Bshareable, options::ONE_DASH, '\0', false,
  663. N_("Generate shared library (alias for -G/-shared)"), NULL);
  664. DEFINE_special (Bno_symbolic, options::ONE_DASH, '\0',
  665. N_ ("Don't bind default visibility defined symbols locally "
  666. "for -shared (default)"),
  667. NULL);
  668. DEFINE_special (Bsymbolic_functions, options::ONE_DASH, '\0',
  669. N_ ("Bind default visibility defined function symbols "
  670. "locally for -shared"),
  671. NULL);
  672. DEFINE_special (
  673. Bsymbolic, options::ONE_DASH, '\0',
  674. N_ ("Bind default visibility defined symbols locally for -shared"),
  675. NULL);
  676. // c
  677. DEFINE_bool(check_sections, options::TWO_DASHES, '\0', true,
  678. N_("Check segment addresses for overlaps"),
  679. N_("Do not check segment addresses for overlaps"));
  680. DEFINE_enum(compress_debug_sections, options::TWO_DASHES, '\0', "none",
  681. N_("Compress .debug_* sections in the output file"),
  682. ("[none,zlib,zlib-gnu,zlib-gabi]"), false,
  683. {"none", "zlib", "zlib-gnu", "zlib-gabi"});
  684. DEFINE_bool(copy_dt_needed_entries, options::TWO_DASHES, '\0', false,
  685. N_("Not supported"),
  686. N_("Do not copy DT_NEEDED tags from shared libraries"));
  687. DEFINE_bool(cref, options::TWO_DASHES, '\0', false,
  688. N_("Output cross reference table"),
  689. N_("Do not output cross reference table"));
  690. DEFINE_bool(ctors_in_init_array, options::TWO_DASHES, '\0', true,
  691. N_("Use DT_INIT_ARRAY for all constructors"),
  692. N_("Handle constructors as directed by compiler"));
  693. // d
  694. DEFINE_bool(define_common, options::TWO_DASHES, 'd', false,
  695. N_("Define common symbols"),
  696. N_("Do not define common symbols in relocatable output"));
  697. DEFINE_bool(dc, options::ONE_DASH, '\0', false,
  698. N_("Alias for -d"), NULL);
  699. DEFINE_bool(dp, options::ONE_DASH, '\0', false,
  700. N_("Alias for -d"), NULL);
  701. DEFINE_string(debug, options::TWO_DASHES, '\0', "",
  702. N_("Turn on debugging"),
  703. N_("[all,files,script,task][,...]"));
  704. DEFINE_special(defsym, options::TWO_DASHES, '\0',
  705. N_("Define a symbol"), N_("SYMBOL=EXPRESSION"));
  706. DEFINE_optional_string(demangle, options::TWO_DASHES, '\0', NULL,
  707. N_("Demangle C++ symbols in log messages"),
  708. N_("[=STYLE]"));
  709. DEFINE_bool(no_demangle, options::TWO_DASHES, '\0', false,
  710. N_("Do not demangle C++ symbols in log messages"),
  711. NULL);
  712. DEFINE_string(dependency_file, options::TWO_DASHES, '\0', NULL,
  713. N_("Write a dependency file listing all files read"),
  714. N_("FILE"));
  715. DEFINE_bool(detect_odr_violations, options::TWO_DASHES, '\0', false,
  716. N_("Look for violations of the C++ One Definition Rule"),
  717. N_("Do not look for violations of the C++ One Definition Rule"));
  718. DEFINE_bool(dynamic_list_data, options::TWO_DASHES, '\0', false,
  719. N_("Add data symbols to dynamic symbols"), NULL);
  720. DEFINE_bool(dynamic_list_cpp_new, options::TWO_DASHES, '\0', false,
  721. N_("Add C++ operator new/delete to dynamic symbols"), NULL);
  722. DEFINE_bool(dynamic_list_cpp_typeinfo, options::TWO_DASHES, '\0', false,
  723. N_("Add C++ typeinfo to dynamic symbols"), NULL);
  724. DEFINE_special(dynamic_list, options::TWO_DASHES, '\0',
  725. N_("Read a list of dynamic symbols"), N_("FILE"));
  726. // e
  727. DEFINE_bool(emit_stub_syms, options::TWO_DASHES, '\0', true,
  728. N_("(PowerPC only) Label linker stubs with a symbol"),
  729. N_("(PowerPC only) Do not label linker stubs with a symbol"));
  730. DEFINE_string(entry, options::TWO_DASHES, 'e', NULL,
  731. N_("Set program start address"), N_("ADDRESS"));
  732. DEFINE_bool(eh_frame_hdr, options::TWO_DASHES, '\0', false,
  733. N_("Create exception frame header"),
  734. N_("Do not create exception frame header"));
  735. // Alphabetized under 'e' because the option is spelled --enable-new-dtags.
  736. DEFINE_enable(new_dtags, options::EXACTLY_TWO_DASHES, '\0', true,
  737. N_("Enable use of DT_RUNPATH"),
  738. N_("Disable use of DT_RUNPATH"));
  739. DEFINE_bool(enum_size_warning, options::TWO_DASHES, '\0', true, NULL,
  740. N_("(ARM only) Do not warn about objects with incompatible "
  741. "enum sizes"));
  742. DEFINE_special(exclude_libs, options::TWO_DASHES, '\0',
  743. N_("Exclude libraries from automatic export"),
  744. N_(("lib,lib ...")));
  745. DEFINE_bool(export_dynamic, options::TWO_DASHES, 'E', false,
  746. N_("Export all dynamic symbols"),
  747. N_("Do not export all dynamic symbols"));
  748. DEFINE_set(export_dynamic_symbol, options::TWO_DASHES, '\0',
  749. N_("Export SYMBOL to dynamic symbol table"), N_("SYMBOL"));
  750. DEFINE_special(EB, options::ONE_DASH, '\0',
  751. N_("Link big-endian objects."), NULL);
  752. DEFINE_special(EL, options::ONE_DASH, '\0',
  753. N_("Link little-endian objects."), NULL);
  754. // f
  755. DEFINE_set(auxiliary, options::TWO_DASHES, 'f',
  756. N_("Auxiliary filter for shared object symbol table"),
  757. N_("SHLIB"));
  758. DEFINE_string(filter, options::TWO_DASHES, 'F', NULL,
  759. N_("Filter for shared object symbol table"),
  760. N_("SHLIB"));
  761. DEFINE_bool(fatal_warnings, options::TWO_DASHES, '\0', false,
  762. N_("Treat warnings as errors"),
  763. N_("Do not treat warnings as errors"));
  764. DEFINE_string(fini, options::ONE_DASH, '\0', "_fini",
  765. N_("Call SYMBOL at unload-time"), N_("SYMBOL"));
  766. DEFINE_bool(fix_arm1176, options::TWO_DASHES, '\0', true,
  767. N_("(ARM only) Fix binaries for ARM1176 erratum"),
  768. N_("(ARM only) Do not fix binaries for ARM1176 erratum"));
  769. DEFINE_bool(fix_cortex_a8, options::TWO_DASHES, '\0', false,
  770. N_("(ARM only) Fix binaries for Cortex-A8 erratum"),
  771. N_("(ARM only) Do not fix binaries for Cortex-A8 erratum"));
  772. DEFINE_bool(fix_cortex_a53_843419, options::TWO_DASHES, '\0', false,
  773. N_("(AArch64 only) Fix Cortex-A53 erratum 843419"),
  774. N_("(AArch64 only) Do not fix Cortex-A53 erratum 843419"));
  775. DEFINE_bool(fix_cortex_a53_835769, options::TWO_DASHES, '\0', false,
  776. N_("(AArch64 only) Fix Cortex-A53 erratum 835769"),
  777. N_("(AArch64 only) Do not fix Cortex-A53 erratum 835769"));
  778. DEFINE_special(fix_v4bx, options::TWO_DASHES, '\0',
  779. N_("(ARM only) Rewrite BX rn as MOV pc, rn for ARMv4"),
  780. NULL);
  781. DEFINE_special(fix_v4bx_interworking, options::TWO_DASHES, '\0',
  782. N_("(ARM only) Rewrite BX rn branch to ARMv4 interworking "
  783. "veneer"),
  784. NULL);
  785. DEFINE_string(fuse_ld, options::ONE_DASH, '\0', "",
  786. N_("Ignored for GCC linker option compatibility"),
  787. N_("[gold,bfd]"));
  788. // g
  789. DEFINE_bool(g, options::EXACTLY_ONE_DASH, '\0', false,
  790. N_("Ignored"), NULL);
  791. DEFINE_bool(gc_sections, options::TWO_DASHES, '\0', false,
  792. N_("Remove unused sections"),
  793. N_("Don't remove unused sections"));
  794. DEFINE_bool(gdb_index, options::TWO_DASHES, '\0', false,
  795. N_("Generate .gdb_index section"),
  796. N_("Do not generate .gdb_index section"));
  797. DEFINE_bool(gnu_unique, options::TWO_DASHES, '\0', true,
  798. N_("Enable STB_GNU_UNIQUE symbol binding"),
  799. N_("Disable STB_GNU_UNIQUE symbol binding"));
  800. DEFINE_bool(shared, options::ONE_DASH, 'G', false,
  801. N_("Generate shared library"), NULL);
  802. // h
  803. DEFINE_string(soname, options::ONE_DASH, 'h', NULL,
  804. N_("Set shared library name"), N_("FILENAME"));
  805. DEFINE_double(hash_bucket_empty_fraction, options::TWO_DASHES, '\0', 0.0,
  806. N_("Min fraction of empty buckets in dynamic hash"),
  807. N_("FRACTION"));
  808. DEFINE_enum(hash_style, options::TWO_DASHES, '\0', DEFAULT_HASH_STYLE,
  809. N_("Dynamic hash style"), N_("[sysv,gnu,both]"), false,
  810. {"sysv", "gnu", "both"});
  811. // i
  812. DEFINE_bool_alias(i, relocatable, options::EXACTLY_ONE_DASH, '\0',
  813. N_("Alias for -r"), NULL, false);
  814. DEFINE_enum(icf, options::TWO_DASHES, '\0', "none",
  815. N_("Identical Code Folding. "
  816. "\'--icf=safe\' Folds ctors, dtors and functions whose"
  817. " pointers are definitely not taken"),
  818. ("[none,all,safe]"), false,
  819. {"none", "all", "safe"});
  820. DEFINE_uint(icf_iterations, options::TWO_DASHES , '\0', 0,
  821. N_("Number of iterations of ICF (default 3)"), N_("COUNT"));
  822. DEFINE_special(incremental, options::TWO_DASHES, '\0',
  823. N_("Do an incremental link if possible; "
  824. "otherwise, do a full link and prepare output "
  825. "for incremental linking"), NULL);
  826. DEFINE_special(no_incremental, options::TWO_DASHES, '\0',
  827. N_("Do a full link (default)"), NULL);
  828. DEFINE_special(incremental_full, options::TWO_DASHES, '\0',
  829. N_("Do a full link and "
  830. "prepare output for incremental linking"), NULL);
  831. DEFINE_special(incremental_update, options::TWO_DASHES, '\0',
  832. N_("Do an incremental link; exit if not possible"), NULL);
  833. DEFINE_string(incremental_base, options::TWO_DASHES, '\0', NULL,
  834. N_("Set base file for incremental linking"
  835. " (default is output file)"),
  836. N_("FILE"));
  837. DEFINE_special(incremental_changed, options::TWO_DASHES, '\0',
  838. N_("Assume files changed"), NULL);
  839. DEFINE_special(incremental_unchanged, options::TWO_DASHES, '\0',
  840. N_("Assume files didn't change"), NULL);
  841. DEFINE_special(incremental_unknown, options::TWO_DASHES, '\0',
  842. N_("Use timestamps to check files (default)"), NULL);
  843. DEFINE_special(incremental_startup_unchanged, options::TWO_DASHES, '\0',
  844. N_("Assume startup files unchanged "
  845. "(files preceding this option)"), NULL);
  846. DEFINE_percent(incremental_patch, options::TWO_DASHES, '\0', 10,
  847. N_("Amount of extra space to allocate for patches "
  848. "(default 10)"),
  849. N_("PERCENT"));
  850. DEFINE_string(init, options::ONE_DASH, '\0', "_init",
  851. N_("Call SYMBOL at load-time"), N_("SYMBOL"));
  852. DEFINE_string(dynamic_linker, options::TWO_DASHES, 'I', NULL,
  853. N_("Set dynamic linker path"), N_("PROGRAM"));
  854. // j
  855. DEFINE_special(just_symbols, options::TWO_DASHES, '\0',
  856. N_("Read only symbol values from FILE"), N_("FILE"));
  857. // k
  858. DEFINE_bool(keep_files_mapped, options::TWO_DASHES, '\0', true,
  859. N_("Keep files mapped across passes"),
  860. N_("Release mapped files after each pass"));
  861. DEFINE_set(keep_unique, options::TWO_DASHES, '\0',
  862. N_("Do not fold this symbol during ICF"), N_("SYMBOL"));
  863. // l
  864. DEFINE_special(library, options::TWO_DASHES, 'l',
  865. N_("Search for library LIBNAME"), N_("LIBNAME"));
  866. DEFINE_bool(ld_generated_unwind_info, options::TWO_DASHES, '\0', true,
  867. N_("Generate unwind information for PLT"),
  868. N_("Do not generate unwind information for PLT"));
  869. DEFINE_dirlist(library_path, options::TWO_DASHES, 'L',
  870. N_("Add directory to search path"), N_("DIR"));
  871. DEFINE_bool(long_plt, options::TWO_DASHES, '\0', false,
  872. N_("(ARM only) Generate long PLT entries"),
  873. N_("(ARM only) Do not generate long PLT entries"));
  874. // m
  875. DEFINE_string(m, options::EXACTLY_ONE_DASH, 'm', "",
  876. N_("Set GNU linker emulation; obsolete"), N_("EMULATION"));
  877. DEFINE_bool(map_whole_files, options::TWO_DASHES, '\0',
  878. sizeof(void*) >= 8,
  879. N_("Map whole files to memory"),
  880. N_("Map relevant file parts to memory"));
  881. DEFINE_bool(merge_exidx_entries, options::TWO_DASHES, '\0', true,
  882. N_("(ARM only) Merge exidx entries in debuginfo"),
  883. N_("(ARM only) Do not merge exidx entries in debuginfo"));
  884. DEFINE_bool(mmap_output_file, options::TWO_DASHES, '\0', true,
  885. N_("Map the output file for writing"),
  886. N_("Do not map the output file for writing"));
  887. DEFINE_bool(print_map, options::TWO_DASHES, 'M', false,
  888. N_("Write map file on standard output"), NULL);
  889. DEFINE_string(Map, options::ONE_DASH, '\0', NULL, N_("Write map file"),
  890. N_("MAPFILENAME"));
  891. // n
  892. DEFINE_bool(nmagic, options::TWO_DASHES, 'n', false,
  893. N_("Do not page align data"), NULL);
  894. DEFINE_bool(omagic, options::EXACTLY_TWO_DASHES, 'N', false,
  895. N_("Do not page align data, do not make text readonly"),
  896. N_("Page align data, make text readonly"));
  897. DEFINE_bool(no_keep_memory, options::TWO_DASHES, '\0', false,
  898. N_("Use less memory and more disk I/O "
  899. "(included only for compatibility with GNU ld)"), NULL);
  900. DEFINE_bool_alias(no_undefined, defs, options::TWO_DASHES, '\0',
  901. N_("Report undefined symbols (even with --shared)"),
  902. NULL, false);
  903. DEFINE_bool(noinhibit_exec, options::TWO_DASHES, '\0', false,
  904. N_("Create an output file even if errors occur"), NULL);
  905. DEFINE_bool(nostdlib, options::ONE_DASH, '\0', false,
  906. N_("Only search directories specified on the command line"),
  907. NULL);
  908. // o
  909. DEFINE_string(output, options::TWO_DASHES, 'o', "a.out",
  910. N_("Set output file name"), N_("FILE"));
  911. DEFINE_string(oformat, options::EXACTLY_TWO_DASHES, '\0', "elf",
  912. N_("Set output format"), N_("[binary]"));
  913. DEFINE_uint(optimize, options::EXACTLY_ONE_DASH, 'O', 0,
  914. N_("Optimize output file size"), N_("LEVEL"));
  915. DEFINE_enum(orphan_handling, options::TWO_DASHES, '\0', "place",
  916. N_("Orphan section handling"), N_("[place,discard,warn,error]"),
  917. false, {"place", "discard", "warn", "error"});
  918. // p
  919. DEFINE_bool(p, options::ONE_DASH, 'p', false,
  920. N_("Ignored for ARM compatibility"), NULL);
  921. DEFINE_bool(pie, options::ONE_DASH, '\0', false,
  922. N_("Create a position independent executable"),
  923. N_("Do not create a position independent executable"));
  924. DEFINE_bool_alias(pic_executable, pie, options::TWO_DASHES, '\0',
  925. N_("Create a position independent executable"),
  926. N_("Do not create a position independent executable"),
  927. false);
  928. DEFINE_bool(pic_veneer, options::TWO_DASHES, '\0', false,
  929. N_("Force PIC sequences for ARM/Thumb interworking veneers"),
  930. NULL);
  931. DEFINE_bool(pipeline_knowledge, options::ONE_DASH, '\0', false,
  932. NULL, N_("(ARM only) Ignore for backward compatibility"));
  933. DEFINE_var(plt_align, options::TWO_DASHES, '\0', 0, "5",
  934. N_("(PowerPC only) Align PLT call stubs to fit cache lines"),
  935. N_("[=P2ALIGN]"), true, int, int, options::parse_uint, false);
  936. DEFINE_bool(plt_localentry, options::TWO_DASHES, '\0', false,
  937. N_("(PowerPC64 only) Optimize calls to ELFv2 localentry:0 functions"),
  938. N_("(PowerPC64 only) Don't optimize ELFv2 calls"));
  939. DEFINE_bool(plt_static_chain, options::TWO_DASHES, '\0', false,
  940. N_("(PowerPC64 only) PLT call stubs should load r11"),
  941. N_("(PowerPC64 only) PLT call stubs should not load r11"));
  942. DEFINE_bool(plt_thread_safe, options::TWO_DASHES, '\0', false,
  943. N_("(PowerPC64 only) PLT call stubs with load-load barrier"),
  944. N_("(PowerPC64 only) PLT call stubs without barrier"));
  945. #ifdef ENABLE_PLUGINS
  946. DEFINE_special(plugin, options::TWO_DASHES, '\0',
  947. N_("Load a plugin library"), N_("PLUGIN"));
  948. DEFINE_special(plugin_opt, options::TWO_DASHES, '\0',
  949. N_("Pass an option to the plugin"), N_("OPTION"));
  950. #else
  951. DEFINE_special(plugin, options::TWO_DASHES, '\0',
  952. N_("Load a plugin library (not supported)"), N_("PLUGIN"));
  953. DEFINE_special(plugin_opt, options::TWO_DASHES, '\0',
  954. N_("Pass an option to the plugin (not supported)"),
  955. N_("OPTION"));
  956. #endif
  957. DEFINE_bool(posix_fallocate, options::TWO_DASHES, '\0', true,
  958. N_("Use posix_fallocate to reserve space in the output file"),
  959. N_("Use fallocate or ftruncate to reserve space"));
  960. DEFINE_enum(power10_stubs, options::TWO_DASHES, '\0', "yes",
  961. N_("(PowerPC64 only) stubs use power10 insns"),
  962. N_("[=auto,no,yes]"), true, {"auto", "no", "yes"});
  963. DEFINE_special(no_power10_stubs, options::TWO_DASHES, '\0',
  964. N_("(PowerPC64 only) stubs do not use power10 insns"), NULL);
  965. DEFINE_bool(preread_archive_symbols, options::TWO_DASHES, '\0', false,
  966. N_("Preread archive symbols when multi-threaded"), NULL);
  967. DEFINE_bool(print_gc_sections, options::TWO_DASHES, '\0', false,
  968. N_("List removed unused sections on stderr"),
  969. N_("Do not list removed unused sections"));
  970. DEFINE_bool(print_icf_sections, options::TWO_DASHES, '\0', false,
  971. N_("List folded identical sections on stderr"),
  972. N_("Do not list folded identical sections"));
  973. DEFINE_bool(print_output_format, options::TWO_DASHES, '\0', false,
  974. N_("Print default output format"), NULL);
  975. DEFINE_string(print_symbol_counts, options::TWO_DASHES, '\0', NULL,
  976. N_("Print symbols defined and used for each input"),
  977. N_("FILENAME"));
  978. DEFINE_special(push_state, options::TWO_DASHES, '\0',
  979. N_("Save the state of flags related to input files"), NULL);
  980. DEFINE_special(pop_state, options::TWO_DASHES, '\0',
  981. N_("Restore the state of flags related to input files"), NULL);
  982. // q
  983. DEFINE_bool(emit_relocs, options::TWO_DASHES, 'q', false,
  984. N_("Generate relocations in output"), NULL);
  985. DEFINE_bool(Qy, options::EXACTLY_ONE_DASH, '\0', false,
  986. N_("Ignored for SVR4 compatibility"), NULL);
  987. // r
  988. DEFINE_bool(relocatable, options::EXACTLY_ONE_DASH, 'r', false,
  989. N_("Generate relocatable output"), NULL);
  990. DEFINE_bool(relax, options::TWO_DASHES, '\0', false,
  991. N_("Relax branches on certain targets"),
  992. N_("Do not relax branches"));
  993. DEFINE_string(retain_symbols_file, options::TWO_DASHES, '\0', NULL,
  994. N_("keep only symbols listed in this file"), N_("FILE"));
  995. DEFINE_bool(rosegment, options::TWO_DASHES, '\0', false,
  996. N_("Put read-only non-executable sections in their own segment"),
  997. N_("Do not put read-only non-executable sections in their own segment"));
  998. DEFINE_uint64(rosegment_gap, options::TWO_DASHES, '\0', -1U,
  999. N_("Set offset between executable and read-only segments"),
  1000. N_("OFFSET"));
  1001. // -R really means -rpath, but can mean --just-symbols for
  1002. // compatibility with GNU ld. -rpath is always -rpath, so we list
  1003. // it separately.
  1004. DEFINE_special(R, options::EXACTLY_ONE_DASH, 'R',
  1005. N_("Add DIR to runtime search path"), N_("DIR"));
  1006. DEFINE_dirlist(rpath, options::ONE_DASH, '\0',
  1007. N_("Add DIR to runtime search path"), N_("DIR"));
  1008. DEFINE_dirlist(rpath_link, options::TWO_DASHES, '\0',
  1009. N_("Add DIR to link time shared library search path"),
  1010. N_("DIR"));
  1011. // s
  1012. DEFINE_bool(strip_all, options::TWO_DASHES, 's', false,
  1013. N_("Strip all symbols"), NULL);
  1014. DEFINE_bool(strip_debug, options::TWO_DASHES, 'S', false,
  1015. N_("Strip debugging information"), NULL);
  1016. DEFINE_bool(strip_debug_non_line, options::TWO_DASHES, '\0', false,
  1017. N_("Emit only debug line number information"), NULL);
  1018. DEFINE_bool(strip_debug_gdb, options::TWO_DASHES, '\0', false,
  1019. N_("Strip debug symbols that are unused by gdb "
  1020. "(at least versions <= 7.4)"), NULL);
  1021. DEFINE_bool(strip_lto_sections, options::TWO_DASHES, '\0', true,
  1022. N_("Strip LTO intermediate code sections"), NULL);
  1023. DEFINE_string(section_ordering_file, options::TWO_DASHES, '\0', NULL,
  1024. N_("Layout sections in the order specified"),
  1025. N_("FILENAME"));
  1026. DEFINE_special(section_start, options::TWO_DASHES, '\0',
  1027. N_("Set address of section"), N_("SECTION=ADDRESS"));
  1028. DEFINE_bool(secure_plt, options::TWO_DASHES , '\0', true,
  1029. N_("(PowerPC only) Use new-style PLT"), NULL);
  1030. DEFINE_optional_string(sort_common, options::TWO_DASHES, '\0', NULL,
  1031. N_("Sort common symbols by alignment"),
  1032. N_("[={ascending,descending}]"));
  1033. DEFINE_enum(sort_section, options::TWO_DASHES, '\0', "none",
  1034. N_("Sort sections by name. \'--no-text-reorder\'"
  1035. " will override \'--sort-section=name\' for .text"),
  1036. N_("[none,name]"), false,
  1037. {"none", "name"});
  1038. DEFINE_uint(spare_dynamic_tags, options::TWO_DASHES, '\0', 5,
  1039. N_("Dynamic tag slots to reserve (default 5)"),
  1040. N_("COUNT"));
  1041. DEFINE_int(stub_group_size, options::TWO_DASHES , '\0', 1,
  1042. N_("(ARM, PowerPC only) The maximum distance from instructions "
  1043. "in a group of sections to their stubs. Negative values mean "
  1044. "stubs are always after the group. 1 means use default size"),
  1045. N_("SIZE"));
  1046. DEFINE_bool(stub_group_multi, options::TWO_DASHES, '\0', true,
  1047. N_("(PowerPC only) Allow a group of stubs to serve multiple "
  1048. "output sections"),
  1049. N_("(PowerPC only) Each output section has its own stubs"));
  1050. DEFINE_uint(split_stack_adjust_size, options::TWO_DASHES, '\0', 0x100000,
  1051. N_("Stack size when -fsplit-stack function calls non-split"),
  1052. N_("SIZE"));
  1053. // This is not actually special in any way, but I need to give it
  1054. // a non-standard accessor-function name because 'static' is a keyword.
  1055. DEFINE_special(static, options::ONE_DASH, '\0',
  1056. N_("Do not link against shared libraries"), NULL);
  1057. DEFINE_special(start_lib, options::TWO_DASHES, '\0',
  1058. N_("Start a library"), NULL);
  1059. DEFINE_special(end_lib, options::TWO_DASHES, '\0',
  1060. N_("End a library "), NULL);
  1061. DEFINE_bool(stats, options::TWO_DASHES, '\0', false,
  1062. N_("Print resource usage statistics"), NULL);
  1063. DEFINE_string(sysroot, options::TWO_DASHES, '\0', "",
  1064. N_("Set target system root directory"), N_("DIR"));
  1065. // t
  1066. DEFINE_bool(trace, options::TWO_DASHES, 't', false,
  1067. N_("Print the name of each input file"), NULL);
  1068. DEFINE_bool(target1_abs, options::TWO_DASHES, '\0', false,
  1069. N_("(ARM only) Force R_ARM_TARGET1 type to R_ARM_ABS32"),
  1070. NULL);
  1071. DEFINE_bool(target1_rel, options::TWO_DASHES, '\0', false,
  1072. N_("(ARM only) Force R_ARM_TARGET1 type to R_ARM_REL32"),
  1073. NULL);
  1074. DEFINE_enum(target2, options::TWO_DASHES, '\0', NULL,
  1075. N_("(ARM only) Set R_ARM_TARGET2 relocation type"),
  1076. N_("[rel, abs, got-rel"), false,
  1077. {"rel", "abs", "got-rel"});
  1078. DEFINE_bool(text_reorder, options::TWO_DASHES, '\0', true,
  1079. N_("Enable text section reordering for GCC section names"),
  1080. N_("Disable text section reordering for GCC section names"));
  1081. DEFINE_bool(threads, options::TWO_DASHES, '\0', false,
  1082. N_("Run the linker multi-threaded"),
  1083. N_("Do not run the linker multi-threaded"));
  1084. DEFINE_uint(thread_count, options::TWO_DASHES, '\0', 0,
  1085. N_("Number of threads to use"), N_("COUNT"));
  1086. DEFINE_uint(thread_count_initial, options::TWO_DASHES, '\0', 0,
  1087. N_("Number of threads to use in initial pass"), N_("COUNT"));
  1088. DEFINE_uint(thread_count_middle, options::TWO_DASHES, '\0', 0,
  1089. N_("Number of threads to use in middle pass"), N_("COUNT"));
  1090. DEFINE_uint(thread_count_final, options::TWO_DASHES, '\0', 0,
  1091. N_("Number of threads to use in final pass"), N_("COUNT"));
  1092. DEFINE_bool(tls_optimize, options::TWO_DASHES, '\0', true,
  1093. N_("(PowerPC/64 only) Optimize GD/LD/IE code to IE/LE"),
  1094. N_("(PowerPC/64 only) Don'\''t try to optimize TLS accesses"));
  1095. DEFINE_bool(tls_get_addr_optimize, options::TWO_DASHES, '\0', true,
  1096. N_("(PowerPC/64 only) Use a special __tls_get_addr call"),
  1097. N_("(PowerPC/64 only) Don't use a special __tls_get_addr call"));
  1098. DEFINE_bool(toc_optimize, options::TWO_DASHES, '\0', true,
  1099. N_("(PowerPC64 only) Optimize TOC code sequences"),
  1100. N_("(PowerPC64 only) Don't optimize TOC code sequences"));
  1101. DEFINE_bool(toc_sort, options::TWO_DASHES, '\0', true,
  1102. N_("(PowerPC64 only) Sort TOC and GOT sections"),
  1103. N_("(PowerPC64 only) Don't sort TOC and GOT sections"));
  1104. DEFINE_special(script, options::TWO_DASHES, 'T',
  1105. N_("Read linker script"), N_("FILE"));
  1106. DEFINE_uint64(Tbss, options::ONE_DASH, '\0', -1U,
  1107. N_("Set the address of the bss segment"), N_("ADDRESS"));
  1108. DEFINE_uint64(Tdata, options::ONE_DASH, '\0', -1U,
  1109. N_("Set the address of the data segment"), N_("ADDRESS"));
  1110. DEFINE_uint64(Ttext, options::ONE_DASH, '\0', -1U,
  1111. N_("Set the address of the text segment"), N_("ADDRESS"));
  1112. DEFINE_uint64_alias(Ttext_segment, Ttext, options::ONE_DASH, '\0',
  1113. N_("Set the address of the text segment"),
  1114. N_("ADDRESS"));
  1115. DEFINE_uint64(Trodata_segment, options::ONE_DASH, '\0', -1U,
  1116. N_("Set the address of the rodata segment"), N_("ADDRESS"));
  1117. // u
  1118. DEFINE_set(undefined, options::TWO_DASHES, 'u',
  1119. N_("Create undefined reference to SYMBOL"), N_("SYMBOL"));
  1120. DEFINE_enum(unresolved_symbols, options::TWO_DASHES, '\0', NULL,
  1121. N_("How to handle unresolved symbols"),
  1122. ("ignore-all,report-all,ignore-in-object-files,"
  1123. "ignore-in-shared-libs"), false,
  1124. {"ignore-all", "report-all", "ignore-in-object-files",
  1125. "ignore-in-shared-libs"});
  1126. // v
  1127. DEFINE_bool(verbose, options::TWO_DASHES, '\0', false,
  1128. N_("Alias for --debug=files"), NULL);
  1129. DEFINE_special(version_script, options::TWO_DASHES, '\0',
  1130. N_("Read version script"), N_("FILE"));
  1131. // w
  1132. DEFINE_bool(warn_common, options::TWO_DASHES, '\0', false,
  1133. N_("Warn about duplicate common symbols"),
  1134. N_("Do not warn about duplicate common symbols"));
  1135. DEFINE_bool_ignore(warn_constructors, options::TWO_DASHES, '\0',
  1136. N_("Ignored"), N_("Ignored"));
  1137. DEFINE_bool(warn_drop_version, options::TWO_DASHES, '\0', false,
  1138. N_("Warn when discarding version information"),
  1139. N_("Do not warn when discarding version information"));
  1140. DEFINE_bool(warn_execstack, options::TWO_DASHES, '\0', false,
  1141. N_("Warn if the stack is executable"),
  1142. N_("Do not warn if the stack is executable"));
  1143. DEFINE_bool(warn_mismatch, options::TWO_DASHES, '\0', true,
  1144. NULL, N_("Don't warn about mismatched input files"));
  1145. DEFINE_bool(warn_multiple_gp, options::TWO_DASHES, '\0', false,
  1146. N_("Ignored"), NULL);
  1147. DEFINE_bool(warn_search_mismatch, options::TWO_DASHES, '\0', true,
  1148. N_("Warn when skipping an incompatible library"),
  1149. N_("Don't warn when skipping an incompatible library"));
  1150. DEFINE_bool(warn_shared_textrel, options::TWO_DASHES, '\0', false,
  1151. N_("Warn if text segment is not shareable"),
  1152. N_("Do not warn if text segment is not shareable"));
  1153. DEFINE_bool(warn_unresolved_symbols, options::TWO_DASHES, '\0', false,
  1154. N_("Report unresolved symbols as warnings"),
  1155. NULL);
  1156. DEFINE_bool_alias(error_unresolved_symbols, warn_unresolved_symbols,
  1157. options::TWO_DASHES, '\0',
  1158. N_("Report unresolved symbols as errors"),
  1159. NULL, true);
  1160. DEFINE_bool(wchar_size_warning, options::TWO_DASHES, '\0', true, NULL,
  1161. N_("(ARM only) Do not warn about objects with incompatible "
  1162. "wchar_t sizes"));
  1163. DEFINE_bool(weak_unresolved_symbols, options::TWO_DASHES, '\0', false,
  1164. N_("Convert unresolved symbols to weak references"),
  1165. NULL);
  1166. DEFINE_bool(whole_archive, options::TWO_DASHES, '\0', false,
  1167. N_("Include all archive contents"),
  1168. N_("Include only needed archive contents"));
  1169. DEFINE_set(wrap, options::TWO_DASHES, '\0',
  1170. N_("Use wrapper functions for SYMBOL"), N_("SYMBOL"));
  1171. // x
  1172. DEFINE_special(discard_all, options::TWO_DASHES, 'x',
  1173. N_("Delete all local symbols"), NULL);
  1174. DEFINE_special(discard_locals, options::TWO_DASHES, 'X',
  1175. N_("Delete all temporary local symbols"), NULL);
  1176. DEFINE_special(discard_none, options::TWO_DASHES, '\0',
  1177. N_("Keep all local symbols"), NULL);
  1178. // y
  1179. DEFINE_set(trace_symbol, options::TWO_DASHES, 'y',
  1180. N_("Trace references to symbol"), N_("SYMBOL"));
  1181. DEFINE_bool(undefined_version, options::TWO_DASHES, '\0', true,
  1182. N_("Allow unused version in script"),
  1183. N_("Do not allow unused version in script"));
  1184. DEFINE_string(Y, options::EXACTLY_ONE_DASH, 'Y', "",
  1185. N_("Default search path for Solaris compatibility"),
  1186. N_("PATH"));
  1187. // special characters
  1188. DEFINE_special(start_group, options::TWO_DASHES, '(',
  1189. N_("Start a library search group"), NULL);
  1190. DEFINE_special(end_group, options::TWO_DASHES, ')',
  1191. N_("End a library search group"), NULL);
  1192. // The -z options.
  1193. DEFINE_bool(bndplt, options::DASH_Z, '\0', false,
  1194. N_("(x86-64 only) Generate a BND PLT for Intel MPX"),
  1195. N_("Generate a regular PLT"));
  1196. DEFINE_bool(combreloc, options::DASH_Z, '\0', true,
  1197. N_("Sort dynamic relocs"),
  1198. N_("Do not sort dynamic relocs"));
  1199. DEFINE_uint64(common_page_size, options::DASH_Z, '\0', 0,
  1200. N_("Set common page size to SIZE"), N_("SIZE"));
  1201. DEFINE_bool(defs, options::DASH_Z, '\0', false,
  1202. N_("Report undefined symbols (even with --shared)"),
  1203. NULL);
  1204. DEFINE_bool(execstack, options::DASH_Z, '\0', false,
  1205. N_("Mark output as requiring executable stack"), NULL);
  1206. DEFINE_bool(global, options::DASH_Z, '\0', false,
  1207. N_("Make symbols in DSO available for subsequently loaded "
  1208. "objects"), NULL);
  1209. DEFINE_bool(initfirst, options::DASH_Z, '\0', false,
  1210. N_("Mark DSO to be initialized first at runtime"),
  1211. NULL);
  1212. DEFINE_bool(interpose, options::DASH_Z, '\0', false,
  1213. N_("Mark object to interpose all DSOs but executable"),
  1214. NULL);
  1215. DEFINE_bool(unique, options::DASH_Z, '\0', false,
  1216. N_("Mark DSO to be loaded at most once, and only in the main namespace"),
  1217. N_("Do not mark the DSO as one to be loaded only in the main namespace"));
  1218. DEFINE_bool_alias(lazy, now, options::DASH_Z, '\0',
  1219. N_("Mark object for lazy runtime binding"),
  1220. NULL, true);
  1221. DEFINE_bool(loadfltr, options::DASH_Z, '\0', false,
  1222. N_("Mark object requiring immediate process"),
  1223. NULL);
  1224. DEFINE_uint64(max_page_size, options::DASH_Z, '\0', 0,
  1225. N_("Set maximum page size to SIZE"), N_("SIZE"));
  1226. DEFINE_bool(muldefs, options::DASH_Z, '\0', false,
  1227. N_("Allow multiple definitions of symbols"),
  1228. NULL);
  1229. // copyreloc is here in the list because there is only -z
  1230. // nocopyreloc, not -z copyreloc.
  1231. DEFINE_bool(copyreloc, options::DASH_Z, '\0', true,
  1232. NULL,
  1233. N_("Do not create copy relocs"));
  1234. DEFINE_bool(nodefaultlib, options::DASH_Z, '\0', false,
  1235. N_("Mark object not to use default search paths"),
  1236. NULL);
  1237. DEFINE_bool(nodelete, options::DASH_Z, '\0', false,
  1238. N_("Mark DSO non-deletable at runtime"),
  1239. NULL);
  1240. DEFINE_bool(nodlopen, options::DASH_Z, '\0', false,
  1241. N_("Mark DSO not available to dlopen"),
  1242. NULL);
  1243. DEFINE_bool(nodump, options::DASH_Z, '\0', false,
  1244. N_("Mark DSO not available to dldump"),
  1245. NULL);
  1246. DEFINE_bool(noexecstack, options::DASH_Z, '\0', false,
  1247. N_("Mark output as not requiring executable stack"), NULL);
  1248. DEFINE_bool(now, options::DASH_Z, '\0', false,
  1249. N_("Mark object for immediate function binding"),
  1250. NULL);
  1251. DEFINE_bool(origin, options::DASH_Z, '\0', false,
  1252. N_("Mark DSO to indicate that needs immediate $ORIGIN "
  1253. "processing at runtime"), NULL);
  1254. DEFINE_bool(relro, options::DASH_Z, '\0', DEFAULT_LD_Z_RELRO,
  1255. N_("Where possible mark variables read-only after relocation"),
  1256. N_("Don't mark variables read-only after relocation"));
  1257. DEFINE_uint64(stack_size, options::DASH_Z, '\0', 0,
  1258. N_("Set PT_GNU_STACK segment p_memsz to SIZE"), N_("SIZE"));
  1259. DEFINE_enum(start_stop_visibility, options::DASH_Z, '\0', "protected",
  1260. N_("ELF symbol visibility for synthesized "
  1261. "__start_* and __stop_* symbols"),
  1262. ("[default,internal,hidden,protected]"), false,
  1263. {"default", "internal", "hidden", "protected"});
  1264. DEFINE_bool(text, options::DASH_Z, '\0', false,
  1265. N_("Do not permit relocations in read-only segments"),
  1266. N_("Permit relocations in read-only segments"));
  1267. DEFINE_bool_alias(textoff, text, options::DASH_Z, '\0',
  1268. N_("Permit relocations in read-only segments"),
  1269. NULL, true);
  1270. DEFINE_bool(text_unlikely_segment, options::DASH_Z, '\0', false,
  1271. N_("Move .text.unlikely sections to a separate segment."),
  1272. N_("Do not move .text.unlikely sections to a separate "
  1273. "segment."));
  1274. DEFINE_bool(keep_text_section_prefix, options::DASH_Z, '\0', false,
  1275. N_("Keep .text.hot, .text.startup, .text.exit and .text.unlikely "
  1276. "as separate sections in the final binary."),
  1277. N_("Merge all .text.* prefix sections."));
  1278. public:
  1279. typedef options::Dir_list Dir_list;
  1280. General_options();
  1281. // Does post-processing on flags, making sure they all have
  1282. // non-conflicting values. Also converts some flags from their
  1283. // "standard" types (string, etc), to another type (enum, DirList),
  1284. // which can be accessed via a separate method. Dies if it notices
  1285. // any problems.
  1286. void finalize();
  1287. // True if we printed the version information.
  1288. bool
  1289. printed_version() const
  1290. { return this->printed_version_; }
  1291. // The macro defines output() (based on --output), but that's a
  1292. // generic name. Provide this alternative name, which is clearer.
  1293. const char*
  1294. output_file_name() const
  1295. { return this->output(); }
  1296. // This is not defined via a flag, but combines flags to say whether
  1297. // the output is position-independent or not.
  1298. bool
  1299. output_is_position_independent() const
  1300. { return this->shared() || this->pie(); }
  1301. // Return true if the output is something that can be exec()ed, such
  1302. // as a static executable, or a position-dependent or
  1303. // position-independent executable, but not a dynamic library or an
  1304. // object file.
  1305. bool
  1306. output_is_executable() const
  1307. { return !this->shared() && !this->relocatable(); }
  1308. // This would normally be static(), and defined automatically, but
  1309. // since static is a keyword, we need to come up with our own name.
  1310. bool
  1311. is_static() const
  1312. { return static_; }
  1313. // In addition to getting the input and output formats as a string
  1314. // (via format() and oformat()), we also give access as an enum.
  1315. enum Object_format
  1316. {
  1317. // Ordinary ELF.
  1318. OBJECT_FORMAT_ELF,
  1319. // Straight binary format.
  1320. OBJECT_FORMAT_BINARY
  1321. };
  1322. // Convert a string to an Object_format. Gives an error if the
  1323. // string is not recognized.
  1324. static Object_format
  1325. string_to_object_format(const char* arg);
  1326. // Convert an Object_format to string.
  1327. static const char*
  1328. object_format_to_string(Object_format);
  1329. // Note: these functions are not very fast.
  1330. Object_format format_enum() const;
  1331. Object_format oformat_enum() const;
  1332. // Return whether FILENAME is in a system directory.
  1333. bool
  1334. is_in_system_directory(const std::string& name) const;
  1335. // RETURN whether SYMBOL_NAME should be kept, according to symbols_to_retain_.
  1336. bool
  1337. should_retain_symbol(const char* symbol_name) const
  1338. {
  1339. if (symbols_to_retain_.empty()) // means flag wasn't specified
  1340. return true;
  1341. return symbols_to_retain_.find(symbol_name) != symbols_to_retain_.end();
  1342. }
  1343. // These are the best way to get access to the execstack state,
  1344. // not execstack() and noexecstack() which are hard to use properly.
  1345. bool
  1346. is_execstack_set() const
  1347. { return this->execstack_status_ != EXECSTACK_FROM_INPUT; }
  1348. bool
  1349. is_stack_executable() const
  1350. { return this->execstack_status_ == EXECSTACK_YES; }
  1351. bool
  1352. icf_enabled() const
  1353. { return this->icf_status_ != ICF_NONE; }
  1354. bool
  1355. icf_safe_folding() const
  1356. { return this->icf_status_ == ICF_SAFE; }
  1357. // The --demangle option takes an optional string, and there is also
  1358. // a --no-demangle option. This is the best way to decide whether
  1359. // to demangle or not.
  1360. bool
  1361. do_demangle() const
  1362. { return this->do_demangle_; }
  1363. // Returns TRUE if any plugin libraries have been loaded.
  1364. bool
  1365. has_plugins() const
  1366. { return this->plugins_ != NULL; }
  1367. // Return a pointer to the plugin manager.
  1368. Plugin_manager*
  1369. plugins() const
  1370. { return this->plugins_; }
  1371. // True iff SYMBOL was found in the file specified by dynamic-list.
  1372. bool
  1373. in_dynamic_list(const char* symbol) const
  1374. { return this->dynamic_list_.version_script_info()->symbol_is_local(symbol); }
  1375. // True if a --dynamic-list script was provided.
  1376. bool
  1377. have_dynamic_list() const
  1378. { return this->have_dynamic_list_; }
  1379. // Finalize the dynamic list.
  1380. void
  1381. finalize_dynamic_list()
  1382. { this->dynamic_list_.version_script_info()->finalize(); }
  1383. // The mode selected by the --incremental options.
  1384. enum Incremental_mode
  1385. {
  1386. // No incremental linking (--no-incremental).
  1387. INCREMENTAL_OFF,
  1388. // Incremental update only (--incremental-update).
  1389. INCREMENTAL_UPDATE,
  1390. // Force a full link, but prepare for subsequent incremental link
  1391. // (--incremental-full).
  1392. INCREMENTAL_FULL,
  1393. // Incremental update if possible, fallback to full link (--incremental).
  1394. INCREMENTAL_AUTO
  1395. };
  1396. // The incremental linking mode.
  1397. Incremental_mode
  1398. incremental_mode() const
  1399. { return this->incremental_mode_; }
  1400. // The disposition given by the --incremental-changed,
  1401. // --incremental-unchanged or --incremental-unknown option. The
  1402. // value may change as we proceed parsing the command line flags.
  1403. Incremental_disposition
  1404. incremental_disposition() const
  1405. { return this->incremental_disposition_; }
  1406. void
  1407. set_incremental_disposition(Incremental_disposition disp)
  1408. { this->incremental_disposition_ = disp; }
  1409. // The disposition to use for startup files (those that precede the
  1410. // first --incremental-changed, etc. option).
  1411. Incremental_disposition
  1412. incremental_startup_disposition() const
  1413. { return this->incremental_startup_disposition_; }
  1414. // Return true if S is the name of a library excluded from automatic
  1415. // symbol export.
  1416. bool
  1417. check_excluded_libs(const std::string &s) const;
  1418. // If an explicit start address was given for section SECNAME with
  1419. // the --section-start option, return true and set *PADDR to the
  1420. // address. Otherwise return false.
  1421. bool
  1422. section_start(const char* secname, uint64_t* paddr) const;
  1423. // Return whether any --section-start option was used.
  1424. bool
  1425. any_section_start() const
  1426. { return !this->section_starts_.empty(); }
  1427. enum Fix_v4bx
  1428. {
  1429. // Leave original instruction.
  1430. FIX_V4BX_NONE,
  1431. // Replace instruction.
  1432. FIX_V4BX_REPLACE,
  1433. // Generate an interworking veneer.
  1434. FIX_V4BX_INTERWORKING
  1435. };
  1436. Fix_v4bx
  1437. fix_v4bx() const
  1438. { return (this->fix_v4bx_); }
  1439. enum Endianness
  1440. {
  1441. ENDIANNESS_NOT_SET,
  1442. ENDIANNESS_BIG,
  1443. ENDIANNESS_LITTLE
  1444. };
  1445. Endianness
  1446. endianness() const
  1447. { return this->endianness_; }
  1448. enum Bsymbolic_kind
  1449. {
  1450. BSYMBOLIC_NONE,
  1451. BSYMBOLIC_FUNCTIONS,
  1452. BSYMBOLIC_ALL,
  1453. };
  1454. bool
  1455. Bsymbolic() const
  1456. { return this->bsymbolic_ == BSYMBOLIC_ALL; }
  1457. bool
  1458. Bsymbolic_functions() const
  1459. { return this->bsymbolic_ == BSYMBOLIC_FUNCTIONS; }
  1460. bool
  1461. discard_all() const
  1462. { return this->discard_locals_ == DISCARD_ALL; }
  1463. bool
  1464. discard_locals() const
  1465. { return this->discard_locals_ == DISCARD_LOCALS; }
  1466. bool
  1467. discard_sec_merge() const
  1468. { return this->discard_locals_ == DISCARD_SEC_MERGE; }
  1469. enum Orphan_handling
  1470. {
  1471. // Place orphan sections normally (default).
  1472. ORPHAN_PLACE,
  1473. // Discard all orphan sections.
  1474. ORPHAN_DISCARD,
  1475. // Warn when placing orphan sections.
  1476. ORPHAN_WARN,
  1477. // Issue error for orphan sections.
  1478. ORPHAN_ERROR
  1479. };
  1480. Orphan_handling
  1481. orphan_handling_enum() const
  1482. { return this->orphan_handling_enum_; }
  1483. elfcpp::STV
  1484. start_stop_visibility_enum() const
  1485. { return this->start_stop_visibility_enum_; }
  1486. enum Power10_stubs
  1487. {
  1488. // Use Power10 insns on @notoc calls/branches, non-Power10 elsewhere.
  1489. POWER10_STUBS_AUTO,
  1490. // Don't use Power10 insns
  1491. POWER10_STUBS_NO,
  1492. // Always use Power10 insns
  1493. POWER10_STUBS_YES
  1494. };
  1495. Power10_stubs
  1496. power10_stubs_enum() const
  1497. { return this->power10_stubs_enum_; }
  1498. private:
  1499. // Don't copy this structure.
  1500. General_options(const General_options&);
  1501. General_options& operator=(const General_options&);
  1502. // What local symbols to discard.
  1503. enum Discard_locals
  1504. {
  1505. // Locals in merge sections (default).
  1506. DISCARD_SEC_MERGE,
  1507. // None (--discard-none).
  1508. DISCARD_NONE,
  1509. // Temporary locals (--discard-locals/-X).
  1510. DISCARD_LOCALS,
  1511. // All locals (--discard-all/-x).
  1512. DISCARD_ALL
  1513. };
  1514. // Whether to mark the stack as executable.
  1515. enum Execstack
  1516. {
  1517. // Not set on command line.
  1518. EXECSTACK_FROM_INPUT,
  1519. // Mark the stack as executable (-z execstack).
  1520. EXECSTACK_YES,
  1521. // Mark the stack as not executable (-z noexecstack).
  1522. EXECSTACK_NO
  1523. };
  1524. enum Icf_status
  1525. {
  1526. // Do not fold any functions (Default or --icf=none).
  1527. ICF_NONE,
  1528. // All functions are candidates for folding. (--icf=all).
  1529. ICF_ALL,
  1530. // Only ctors and dtors are candidates for folding. (--icf=safe).
  1531. ICF_SAFE
  1532. };
  1533. void
  1534. set_icf_status(Icf_status value)
  1535. { this->icf_status_ = value; }
  1536. void
  1537. set_execstack_status(Execstack value)
  1538. { this->execstack_status_ = value; }
  1539. void
  1540. set_do_demangle(bool value)
  1541. { this->do_demangle_ = value; }
  1542. void
  1543. set_static(bool value)
  1544. { static_ = value; }
  1545. void
  1546. set_orphan_handling_enum(Orphan_handling value)
  1547. { this->orphan_handling_enum_ = value; }
  1548. void
  1549. set_start_stop_visibility_enum(elfcpp::STV value)
  1550. { this->start_stop_visibility_enum_ = value; }
  1551. void
  1552. set_power10_stubs_enum(Power10_stubs value)
  1553. { this->power10_stubs_enum_ = value; }
  1554. // These are called by finalize() to set up the search-path correctly.
  1555. void
  1556. add_to_library_path_with_sysroot(const std::string& arg)
  1557. { this->add_search_directory_to_library_path(Search_directory(arg, true)); }
  1558. // Apply any sysroot to the directory lists.
  1559. void
  1560. add_sysroot();
  1561. // Add a plugin and its arguments to the list of plugins.
  1562. void
  1563. add_plugin(const char* filename);
  1564. // Add a plugin option.
  1565. void
  1566. add_plugin_option(const char* opt);
  1567. void
  1568. copy_from_posdep_options(const Position_dependent_options&);
  1569. // Whether we bind default visibility defined symbols locally for -shared.
  1570. Bsymbolic_kind bsymbolic_;
  1571. // Whether we printed version information.
  1572. bool printed_version_;
  1573. // Whether to mark the stack as executable.
  1574. Execstack execstack_status_;
  1575. // Whether to do code folding.
  1576. Icf_status icf_status_;
  1577. // Whether to do a static link.
  1578. bool static_;
  1579. // Whether to do demangling.
  1580. bool do_demangle_;
  1581. // List of plugin libraries.
  1582. Plugin_manager* plugins_;
  1583. // The parsed output of --dynamic-list files. For convenience in
  1584. // script.cc, we store this as a Script_options object, even though
  1585. // we only use a single Version_tree from it.
  1586. Script_options dynamic_list_;
  1587. // Whether a --dynamic-list file was provided.
  1588. bool have_dynamic_list_;
  1589. // The incremental linking mode.
  1590. Incremental_mode incremental_mode_;
  1591. // The disposition given by the --incremental-changed,
  1592. // --incremental-unchanged or --incremental-unknown option. The
  1593. // value may change as we proceed parsing the command line flags.
  1594. Incremental_disposition incremental_disposition_;
  1595. // The disposition to use for startup files (those marked
  1596. // INCREMENTAL_STARTUP).
  1597. Incremental_disposition incremental_startup_disposition_;
  1598. // Whether we have seen one of the options that require incremental
  1599. // build (--incremental-changed, --incremental-unchanged,
  1600. // --incremental-unknown, or --incremental-startup-unchanged).
  1601. bool implicit_incremental_;
  1602. // Libraries excluded from automatic export, via --exclude-libs.
  1603. Unordered_set<std::string> excluded_libs_;
  1604. // List of symbol-names to keep, via -retain-symbol-info.
  1605. Unordered_set<std::string> symbols_to_retain_;
  1606. // Map from section name to address from --section-start.
  1607. std::map<std::string, uint64_t> section_starts_;
  1608. // Whether to process armv4 bx instruction relocation.
  1609. Fix_v4bx fix_v4bx_;
  1610. // Endianness.
  1611. Endianness endianness_;
  1612. // What local symbols to discard.
  1613. Discard_locals discard_locals_;
  1614. // Stack of saved options for --push-state/--pop-state.
  1615. std::vector<Position_dependent_options*> options_stack_;
  1616. // Orphan handling option, decoded to an enum value.
  1617. Orphan_handling orphan_handling_enum_;
  1618. // Symbol visibility for __start_* / __stop_* magic symbols.
  1619. elfcpp::STV start_stop_visibility_enum_;
  1620. // Power10 stubs option
  1621. Power10_stubs power10_stubs_enum_;
  1622. };
  1623. // The position-dependent options. We use this to store the state of
  1624. // the commandline at a particular point in parsing for later
  1625. // reference. For instance, if we see "ld --whole-archive foo.a
  1626. // --no-whole-archive," we want to store the whole-archive option with
  1627. // foo.a, so when the time comes to parse foo.a we know we should do
  1628. // it in whole-archive mode. We could store all of General_options,
  1629. // but that's big, so we just pick the subset of flags that actually
  1630. // change in a position-dependent way.
  1631. #define DEFINE_posdep(varname__, type__) \
  1632. public: \
  1633. type__ \
  1634. varname__() const \
  1635. { return this->varname__##_; } \
  1636. \
  1637. void \
  1638. set_##varname__(type__ value) \
  1639. { this->varname__##_ = value; } \
  1640. private: \
  1641. type__ varname__##_
  1642. class Position_dependent_options
  1643. {
  1644. public:
  1645. Position_dependent_options(const General_options& options
  1646. = Position_dependent_options::default_options_)
  1647. { copy_from_options(options); }
  1648. void
  1649. copy_from_options(const General_options& options)
  1650. {
  1651. this->set_as_needed(options.as_needed());
  1652. this->set_Bdynamic(options.Bdynamic());
  1653. this->set_format_enum(options.format_enum());
  1654. this->set_whole_archive(options.whole_archive());
  1655. this->set_incremental_disposition(options.incremental_disposition());
  1656. }
  1657. DEFINE_posdep(as_needed, bool);
  1658. DEFINE_posdep(Bdynamic, bool);
  1659. DEFINE_posdep(format_enum, General_options::Object_format);
  1660. DEFINE_posdep(whole_archive, bool);
  1661. DEFINE_posdep(incremental_disposition, Incremental_disposition);
  1662. private:
  1663. // This is a General_options with everything set to its default
  1664. // value. A Position_dependent_options created with no argument
  1665. // will take its values from here.
  1666. static General_options default_options_;
  1667. };
  1668. // A single file or library argument from the command line.
  1669. class Input_file_argument
  1670. {
  1671. public:
  1672. enum Input_file_type
  1673. {
  1674. // A regular file, name used as-is, not searched.
  1675. INPUT_FILE_TYPE_FILE,
  1676. // A library name. When used, "lib" will be prepended and ".so" or
  1677. // ".a" appended to make a filename, and that filename will be searched
  1678. // for using the -L paths.
  1679. INPUT_FILE_TYPE_LIBRARY,
  1680. // A regular file, name used as-is, but searched using the -L paths.
  1681. INPUT_FILE_TYPE_SEARCHED_FILE
  1682. };
  1683. // name: file name or library name
  1684. // type: the type of this input file.
  1685. // extra_search_path: an extra directory to look for the file, prior
  1686. // to checking the normal library search path. If this is "",
  1687. // then no extra directory is added.
  1688. // just_symbols: whether this file only defines symbols.
  1689. // options: The position dependent options at this point in the
  1690. // command line, such as --whole-archive.
  1691. Input_file_argument()
  1692. : name_(), type_(INPUT_FILE_TYPE_FILE), extra_search_path_(""),
  1693. just_symbols_(false), options_(), arg_serial_(0)
  1694. { }
  1695. Input_file_argument(const char* name, Input_file_type type,
  1696. const char* extra_search_path,
  1697. bool just_symbols,
  1698. const Position_dependent_options& options)
  1699. : name_(name), type_(type), extra_search_path_(extra_search_path),
  1700. just_symbols_(just_symbols), options_(options), arg_serial_(0)
  1701. { }
  1702. // You can also pass in a General_options instance instead of a
  1703. // Position_dependent_options. In that case, we extract the
  1704. // position-independent vars from the General_options and only store
  1705. // those.
  1706. Input_file_argument(const char* name, Input_file_type type,
  1707. const char* extra_search_path,
  1708. bool just_symbols,
  1709. const General_options& options)
  1710. : name_(name), type_(type), extra_search_path_(extra_search_path),
  1711. just_symbols_(just_symbols), options_(options), arg_serial_(0)
  1712. { }
  1713. const char*
  1714. name() const
  1715. { return this->name_.c_str(); }
  1716. const Position_dependent_options&
  1717. options() const
  1718. { return this->options_; }
  1719. bool
  1720. is_lib() const
  1721. { return type_ == INPUT_FILE_TYPE_LIBRARY; }
  1722. bool
  1723. is_searched_file() const
  1724. { return type_ == INPUT_FILE_TYPE_SEARCHED_FILE; }
  1725. const char*
  1726. extra_search_path() const
  1727. {
  1728. return (this->extra_search_path_.empty()
  1729. ? NULL
  1730. : this->extra_search_path_.c_str());
  1731. }
  1732. // Return whether we should only read symbols from this file.
  1733. bool
  1734. just_symbols() const
  1735. { return this->just_symbols_; }
  1736. // Return whether this file may require a search using the -L
  1737. // options.
  1738. bool
  1739. may_need_search() const
  1740. {
  1741. return (this->is_lib()
  1742. || this->is_searched_file()
  1743. || !this->extra_search_path_.empty());
  1744. }
  1745. // Set the serial number for this argument.
  1746. void
  1747. set_arg_serial(unsigned int arg_serial)
  1748. { this->arg_serial_ = arg_serial; }
  1749. // Get the serial number.
  1750. unsigned int
  1751. arg_serial() const
  1752. { return this->arg_serial_; }
  1753. private:
  1754. // We use std::string, not const char*, here for convenience when
  1755. // using script files, so that we do not have to preserve the string
  1756. // in that case.
  1757. std::string name_;
  1758. Input_file_type type_;
  1759. std::string extra_search_path_;
  1760. bool just_symbols_;
  1761. Position_dependent_options options_;
  1762. // A unique index for this file argument in the argument list.
  1763. unsigned int arg_serial_;
  1764. };
  1765. // A file or library, or a group, from the command line.
  1766. class Input_argument
  1767. {
  1768. public:
  1769. // Create a file or library argument.
  1770. explicit Input_argument(Input_file_argument file)
  1771. : is_file_(true), file_(file), group_(NULL), lib_(NULL), script_info_(NULL)
  1772. { }
  1773. // Create a group argument.
  1774. explicit Input_argument(Input_file_group* group)
  1775. : is_file_(false), group_(group), lib_(NULL), script_info_(NULL)
  1776. { }
  1777. // Create a lib argument.
  1778. explicit Input_argument(Input_file_lib* lib)
  1779. : is_file_(false), group_(NULL), lib_(lib), script_info_(NULL)
  1780. { }
  1781. // Return whether this is a file.
  1782. bool
  1783. is_file() const
  1784. { return this->is_file_; }
  1785. // Return whether this is a group.
  1786. bool
  1787. is_group() const
  1788. { return !this->is_file_ && this->lib_ == NULL; }
  1789. // Return whether this is a lib.
  1790. bool
  1791. is_lib() const
  1792. { return this->lib_ != NULL; }
  1793. // Return the information about the file.
  1794. const Input_file_argument&
  1795. file() const
  1796. {
  1797. gold_assert(this->is_file_);
  1798. return this->file_;
  1799. }
  1800. // Return the information about the group.
  1801. const Input_file_group*
  1802. group() const
  1803. {
  1804. gold_assert(!this->is_file_);
  1805. return this->group_;
  1806. }
  1807. Input_file_group*
  1808. group()
  1809. {
  1810. gold_assert(!this->is_file_);
  1811. return this->group_;
  1812. }
  1813. // Return the information about the lib.
  1814. const Input_file_lib*
  1815. lib() const
  1816. {
  1817. gold_assert(!this->is_file_);
  1818. gold_assert(this->lib_);
  1819. return this->lib_;
  1820. }
  1821. Input_file_lib*
  1822. lib()
  1823. {
  1824. gold_assert(!this->is_file_);
  1825. gold_assert(this->lib_);
  1826. return this->lib_;
  1827. }
  1828. // If a script generated this argument, store a pointer to the script info.
  1829. // Currently used only for recording incremental link information.
  1830. void
  1831. set_script_info(Script_info* info)
  1832. { this->script_info_ = info; }
  1833. Script_info*
  1834. script_info() const
  1835. { return this->script_info_; }
  1836. private:
  1837. bool is_file_;
  1838. Input_file_argument file_;
  1839. Input_file_group* group_;
  1840. Input_file_lib* lib_;
  1841. Script_info* script_info_;
  1842. };
  1843. typedef std::vector<Input_argument> Input_argument_list;
  1844. // A group from the command line. This is a set of arguments within
  1845. // --start-group ... --end-group.
  1846. class Input_file_group
  1847. {
  1848. public:
  1849. typedef Input_argument_list::const_iterator const_iterator;
  1850. Input_file_group()
  1851. : files_()
  1852. { }
  1853. // Add a file to the end of the group.
  1854. Input_argument&
  1855. add_file(const Input_file_argument& arg)
  1856. {
  1857. this->files_.push_back(Input_argument(arg));
  1858. return this->files_.back();
  1859. }
  1860. // Iterators to iterate over the group contents.
  1861. const_iterator
  1862. begin() const
  1863. { return this->files_.begin(); }
  1864. const_iterator
  1865. end() const
  1866. { return this->files_.end(); }
  1867. private:
  1868. Input_argument_list files_;
  1869. };
  1870. // A lib from the command line. This is a set of arguments within
  1871. // --start-lib ... --end-lib.
  1872. class Input_file_lib
  1873. {
  1874. public:
  1875. typedef Input_argument_list::const_iterator const_iterator;
  1876. Input_file_lib(const Position_dependent_options& options)
  1877. : files_(), options_(options)
  1878. { }
  1879. // Add a file to the end of the lib.
  1880. Input_argument&
  1881. add_file(const Input_file_argument& arg)
  1882. {
  1883. this->files_.push_back(Input_argument(arg));
  1884. return this->files_.back();
  1885. }
  1886. const Position_dependent_options&
  1887. options() const
  1888. { return this->options_; }
  1889. // Iterators to iterate over the lib contents.
  1890. const_iterator
  1891. begin() const
  1892. { return this->files_.begin(); }
  1893. const_iterator
  1894. end() const
  1895. { return this->files_.end(); }
  1896. size_t
  1897. size() const
  1898. { return this->files_.size(); }
  1899. private:
  1900. Input_argument_list files_;
  1901. Position_dependent_options options_;
  1902. };
  1903. // A list of files from the command line or a script.
  1904. class Input_arguments
  1905. {
  1906. public:
  1907. typedef Input_argument_list::const_iterator const_iterator;
  1908. Input_arguments()
  1909. : input_argument_list_(), in_group_(false), in_lib_(false), file_count_(0)
  1910. { }
  1911. // Add a file.
  1912. Input_argument&
  1913. add_file(Input_file_argument& arg);
  1914. // Start a group (the --start-group option).
  1915. void
  1916. start_group();
  1917. // End a group (the --end-group option).
  1918. void
  1919. end_group();
  1920. // Start a lib (the --start-lib option).
  1921. void
  1922. start_lib(const Position_dependent_options&);
  1923. // End a lib (the --end-lib option).
  1924. void
  1925. end_lib();
  1926. // Return whether we are currently in a group.
  1927. bool
  1928. in_group() const
  1929. { return this->in_group_; }
  1930. // Return whether we are currently in a lib.
  1931. bool
  1932. in_lib() const
  1933. { return this->in_lib_; }
  1934. // The number of entries in the list.
  1935. int
  1936. size() const
  1937. { return this->input_argument_list_.size(); }
  1938. // Iterators to iterate over the list of input files.
  1939. const_iterator
  1940. begin() const
  1941. { return this->input_argument_list_.begin(); }
  1942. const_iterator
  1943. end() const
  1944. { return this->input_argument_list_.end(); }
  1945. // Return whether the list is empty.
  1946. bool
  1947. empty() const
  1948. { return this->input_argument_list_.empty(); }
  1949. // Return the number of input files. This may be larger than
  1950. // input_argument_list_.size(), because of files that are part
  1951. // of groups or libs.
  1952. int
  1953. number_of_input_files() const
  1954. { return this->file_count_; }
  1955. private:
  1956. Input_argument_list input_argument_list_;
  1957. bool in_group_;
  1958. bool in_lib_;
  1959. unsigned int file_count_;
  1960. };
  1961. // All the information read from the command line. These are held in
  1962. // three separate structs: one to hold the options (--foo), one to
  1963. // hold the filenames listed on the commandline, and one to hold
  1964. // linker script information. This third is not a subset of the other
  1965. // two because linker scripts can be specified either as options (via
  1966. // -T) or as a file.
  1967. class Command_line
  1968. {
  1969. public:
  1970. typedef Input_arguments::const_iterator const_iterator;
  1971. Command_line();
  1972. // Process the command line options. This will exit with an
  1973. // appropriate error message if an unrecognized option is seen.
  1974. void
  1975. process(int argc, const char** argv);
  1976. // Process one command-line option. This takes the index of argv to
  1977. // process, and returns the index for the next option. no_more_options
  1978. // is set to true if argv[i] is "--".
  1979. int
  1980. process_one_option(int argc, const char** argv, int i,
  1981. bool* no_more_options);
  1982. // Get the general options.
  1983. const General_options&
  1984. options() const
  1985. { return this->options_; }
  1986. // Get the position dependent options.
  1987. const Position_dependent_options&
  1988. position_dependent_options() const
  1989. { return this->position_options_; }
  1990. // Get the linker-script options.
  1991. Script_options&
  1992. script_options()
  1993. { return this->script_options_; }
  1994. // Finalize the version-script options and return them.
  1995. const Version_script_info&
  1996. version_script();
  1997. // Get the input files.
  1998. Input_arguments&
  1999. inputs()
  2000. { return this->inputs_; }
  2001. // The number of input files.
  2002. int
  2003. number_of_input_files() const
  2004. { return this->inputs_.number_of_input_files(); }
  2005. // Iterators to iterate over the list of input files.
  2006. const_iterator
  2007. begin() const
  2008. { return this->inputs_.begin(); }
  2009. const_iterator
  2010. end() const
  2011. { return this->inputs_.end(); }
  2012. private:
  2013. Command_line(const Command_line&);
  2014. Command_line& operator=(const Command_line&);
  2015. // This is a dummy class to provide a constructor that runs before
  2016. // the constructor for the General_options. The Pre_options constructor
  2017. // is used as a hook to set the flag enabling the options to register
  2018. // themselves.
  2019. struct Pre_options {
  2020. Pre_options();
  2021. };
  2022. // This must come before options_!
  2023. Pre_options pre_options_;
  2024. General_options options_;
  2025. Position_dependent_options position_options_;
  2026. Script_options script_options_;
  2027. Input_arguments inputs_;
  2028. };
  2029. } // End namespace gold.
  2030. #endif // !defined(GOLD_OPTIONS_H)