Skip to content

Commit d1188f7

Browse files
committedJun 21, 2016
Accept both single and double dashes for all options.
This is a follow-up patch to r273218. GNU ld accepts both "--" and "-" for all multi-letter options except "-o". This patch makes lld compatible with that behavior. llvm-svn: 273256
1 parent 1181192 commit d1188f7

File tree

1 file changed

+178
-137
lines changed

1 file changed

+178
-137
lines changed
 

‎lld/ELF/Options.td

+178-137
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,209 @@
11
include "llvm/Option/OptParser.td"
22

3-
// Flag that takes no arguments.
43
// For options whose names are multiple letters, either one dash or
54
// two can precede the option name except those that start with 'o'.
6-
class F<string name, string help>: Flag<["--", "-"], name>, HelpText<help>;
5+
class F<string name>: Flag<["--", "-"], name>;
6+
class J<string name>: Joined<["--", "-"], name>;
7+
class S<string name>: Separate<["--", "-"], name>;
8+
class JS<string name>: JoinedOrSeparate<["--", "-"], name>;
79

8-
def Bsymbolic: F<"Bsymbolic", "Bind defined symbols locally">;
9-
def Bsymbolic_functions: F<"Bsymbolic-functions", "Bind defined function symbols locally">;
10-
def Bdynamic: F<"Bdynamic", "Link against shared libraries">;
11-
def Bstatic: F<"Bstatic", "Do not link against shared libraries">;
12-
def build_id: F<"build-id", "Generate build ID note">;
10+
def Bsymbolic: F<"Bsymbolic">, HelpText<"Bind defined symbols locally">;
1311

14-
def build_id_eq : Joined<["--", "-"], "build-id=">;
12+
def Bsymbolic_functions: F<"Bsymbolic-functions">,
13+
HelpText<"Bind defined function symbols locally">;
1514

16-
def L : JoinedOrSeparate<["-"], "L">, MetaVarName<"<dir>">,
15+
def Bdynamic: F<"Bdynamic">, HelpText<"Link against shared libraries">;
16+
17+
def Bstatic: F<"Bstatic">, HelpText<"Do not link against shared libraries">;
18+
19+
def build_id: F<"build-id">, HelpText<"Generate build ID note">;
20+
21+
def build_id_eq: J<"build-id=">, HelpText<"Generate build ID note">;
22+
23+
def L: JS<"L">, MetaVarName<"<dir>">,
1724
HelpText<"Add a directory to the library search path">;
1825

19-
def O : Joined<["-"], "O">, HelpText<"Optimize">;
26+
def O: J<"O">, HelpText<"Optimize output file size">;
27+
28+
def allow_multiple_definition: F<"allow-multiple-definition">,
29+
HelpText<"Allow multiple definitions">;
30+
31+
def as_needed: F<"as-needed">,
32+
HelpText<"Only set DT_NEEDED for shared libraries if used">;
2033

21-
def allow_multiple_definition: F<"allow-multiple-definition", "Allow multiple definitions">;
22-
def as_needed: F<"as-needed", "Only set DT_NEEDED for shared libraries if used">;
23-
def disable_new_dtags: F<"disable-new-dtags", "Disable new dynamic tags">;
24-
def discard_all: F<"discard-all", "Delete all local symbols">;
25-
def discard_locals: F<"discard-locals", "Delete temporary local symbols">;
26-
def discard_none: F<"discard-none", "Keep all symbols in the symbol table">;
34+
def disable_new_dtags: F<"disable-new-dtags">,
35+
HelpText<"Disable new dynamic tags">;
2736

28-
def dynamic_linker : Separate<["--", "-"], "dynamic-linker">,
37+
def discard_all: F<"discard-all">, HelpText<"Delete all local symbols">;
38+
39+
def discard_locals: F<"discard-locals">,
40+
HelpText<"Delete temporary local symbols">;
41+
42+
def discard_none: F<"discard-none">,
43+
HelpText<"Keep all symbols in the symbol table">;
44+
45+
def dynamic_linker: S<"dynamic-linker">,
2946
HelpText<"Which dynamic linker to use">;
3047

31-
def dynamic_list : Separate<["--", "-"], "dynamic-list">,
48+
def dynamic_list: S<"dynamic-list">,
3249
HelpText<"Read a list of dynamic symbols">;
3350

34-
def eh_frame_hdr: F<"eh-frame-hdr", "Request creation of .eh_frame_hdr section and PT_GNU_EH_FRAME segment header">;
35-
def enable_new_dtags: F<"enable-new-dtags", "Enable new dynamic tags">;
36-
def end_lib: F<"end-lib", "End a grouping of objects that should be treated as if they were together in an archive">;
51+
def eh_frame_hdr: F<"eh-frame-hdr">,
52+
HelpText<"Request creation of .eh_frame_hdr section and PT_GNU_EH_FRAME segment header">;
3753

38-
def entry : Separate<["--", "-"], "entry">, MetaVarName<"<entry>">,
54+
def enable_new_dtags: F<"enable-new-dtags">,
55+
HelpText<"Enable new dynamic tags">;
56+
57+
def end_lib: F<"end-lib">,
58+
HelpText<"End a grouping of objects that should be treated as if they were together in an archive">;
59+
60+
def entry: S<"entry">, MetaVarName<"<entry>">,
3961
HelpText<"Name of entry point symbol">;
4062

41-
def export_dynamic: F<"export-dynamic", "Put symbols in the dynamic symbol table">;
63+
def export_dynamic: F<"export-dynamic">,
64+
HelpText<"Put symbols in the dynamic symbol table">;
4265

43-
def export_dynamic_symbol : Separate<["--", "-"], "export-dynamic-symbol">,
66+
def export_dynamic_symbol: S<"export-dynamic-symbol">,
4467
HelpText<"Put a symbol in the dynamic symbol table">;
4568

46-
def fini : Separate<["-"], "fini">, MetaVarName<"<symbol>">,
69+
def fini: S<"fini">, MetaVarName<"<symbol>">,
4770
HelpText<"Specify a finalizer function">;
4871

49-
def hash_style : Separate<["--", "-"], "hash-style">,
72+
def hash_style: S<"hash-style">,
5073
HelpText<"Specify hash style (sysv, gnu or both)">;
5174

52-
def help: F<"help", "Print option help">;
53-
def icf: F<"icf=all", "Enable identical code folding">;
54-
def gc_sections: F<"gc-sections", "Enable garbage collection of unused sections">;
75+
def help: F<"help">, HelpText<"Print option help">;
76+
77+
def icf: F<"icf=all">, HelpText<"Enable identical code folding">;
5578

56-
def init : Separate<["-"], "init">, MetaVarName<"<symbol>">,
79+
def gc_sections: F<"gc-sections">,
80+
HelpText<"Enable garbage collection of unused sections">;
81+
82+
def init: S<"init">, MetaVarName<"<symbol>">,
5783
HelpText<"Specify an initializer function">;
5884

59-
def l : JoinedOrSeparate<["-"], "l">, MetaVarName<"<libName>">,
85+
def l: JS<"l">, MetaVarName<"<libName>">,
6086
HelpText<"Root name of library to use">;
6187

62-
def lto_O : Joined<["--"], "lto-O">, MetaVarName<"<opt-level>">,
88+
def lto_O: J<"lto-O">, MetaVarName<"<opt-level>">,
6389
HelpText<"Optimization level for LTO">;
6490

65-
def m : JoinedOrSeparate<["-"], "m">,
66-
HelpText<"Set target emulation">;
91+
def m: JS<"m">, HelpText<"Set target emulation">;
92+
93+
def no_as_needed: F<"no-as-needed">,
94+
HelpText<"Always DT_NEEDED for shared libraries">;
95+
96+
def no_demangle: F<"no-demangle">,
97+
HelpText<"Do not demangle symbol names">;
98+
99+
def no_gnu_unique: F<"no-gnu-unique">,
100+
HelpText<"Disable STB_GNU_UNIQUE symbol binding">;
101+
102+
def no_whole_archive: F<"no-whole-archive">,
103+
HelpText<"Restores the default behavior of loading archive members">;
104+
105+
def noinhibit_exec: F<"noinhibit-exec">,
106+
HelpText<"Retain the executable output file whenever it is still usable">;
67107

68-
def no_as_needed: F<"no-as-needed", "Always DT_NEEDED for shared libraries">;
69-
def no_demangle: F<"no-demangle", "Do not demangle symbol names">;
70-
def no_gnu_unique: F<"no-gnu-unique", "Disable STB_GNU_UNIQUE symbol binding">;
71-
def no_whole_archive: F<"no-whole-archive", "Restores the default behavior of loading archive members">;
72-
def noinhibit_exec: F<"noinhibit-exec", "Retain the executable output file whenever it is still usable">;
73-
def no_undefined: F<"no-undefined", "Report unresolved symbols even if the linker is creating a shared library">;
108+
def no_undefined: F<"no-undefined">,
109+
HelpText<"Report unresolved symbols even if the linker is creating a shared library">;
74110

75-
def o : JoinedOrSeparate<["-"], "o">, MetaVarName<"<path>">,
111+
def o: JoinedOrSeparate<["-"], "o">, MetaVarName<"<path>">,
76112
HelpText<"Path to file to write output">;
77113

78-
def pie: F<"pie", "Create a position independent executable">;
79-
def print_gc_sections: F<"print-gc-sections", "List removed unused sections">;
114+
def pie: F<"pie">, HelpText<"Create a position independent executable">;
80115

81-
def reproduce : Separate<["--"], "reproduce">,
116+
def print_gc_sections: F<"print-gc-sections">,
117+
HelpText<"List removed unused sections">;
118+
119+
def reproduce: S<"reproduce">,
82120
HelpText<"Dump linker invocation and input files for debugging">;
83121

84-
def rpath : Separate<["-"], "rpath">,
85-
HelpText<"Add a DT_RUNPATH to the output">;
122+
def rpath: S<"rpath">, HelpText<"Add a DT_RUNPATH to the output">;
123+
124+
def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">;
125+
126+
def script: S<"script">, HelpText<"Read linker script">;
86127

87-
def relocatable: F<"relocatable", "Create relocatable object file">;
128+
def shared: F<"shared">, HelpText<"Build a shared object">;
88129

89-
def script : Separate<["--"], "script">,
90-
HelpText<"Read linker script">;
130+
def soname: J<"soname=">, HelpText<"Set DT_SONAME">;
91131

92-
def shared: F<"shared", "Build a shared object">;
132+
def start_lib: F<"start-lib">,
133+
HelpText<"Start a grouping of objects that should be treated as if they were together in an archive">;
93134

94-
def soname : Joined<["-", "--"], "soname=">,
95-
HelpText<"Set DT_SONAME">;
135+
def strip_all: F<"strip-all">, HelpText<"Strip all symbols">;
96136

97-
def start_lib: F<"start-lib", "Start a grouping of objects that should be treated as if they were together in an archive">;
98-
def strip_all: F<"strip-all", "Strip all symbols">;
99-
def strip_debug: F<"strip-debug", "Strip debugging information">;
137+
def strip_debug: F<"strip-debug">, HelpText<"Strip debugging information">;
100138

101-
def sysroot : Joined<["--"], "sysroot=">,
102-
HelpText<"Set the system root">;
139+
def sysroot: J<"sysroot=">, HelpText<"Set the system root">;
103140

104-
def threads: F<"threads", "Enable use of threads">;
105-
def trace: F<"trace", "Print the names of the input files">;
141+
def threads: F<"threads">, HelpText<"Enable use of threads">;
106142

107-
def undefined : Joined<["--"], "undefined=">,
143+
def trace: F<"trace">, HelpText<"Print the names of the input files">;
144+
145+
def undefined: J<"undefined=">,
108146
HelpText<"Force undefined symbol during linking">;
109147

110-
def verbose: F<"verbose", "Verbose mode">;
111-
def version: F<"version", "Display the version number">;
148+
def verbose: F<"verbose">, HelpText<"Verbose mode">;
149+
150+
def version: F<"version">, HelpText<"Display the version number">;
112151

113-
def version_script : Separate<["--", "-"], "version-script">,
152+
def version_script: S<"version-script">,
114153
HelpText<"Read a version script">;
115154

116-
def warn_common: F<"warn-common", "Warn about duplicate common symbols">;
117-
def whole_archive: F<"whole-archive", "Force load of all members in a static library">;
155+
def warn_common: F<"warn-common">,
156+
HelpText<"Warn about duplicate common symbols">;
157+
158+
def whole_archive: F<"whole-archive">,
159+
HelpText<"Force load of all members in a static library">;
118160

119-
def wrap : Separate<["--", "-"], "wrap">, MetaVarName<"<symbol>">,
161+
def wrap: S<"wrap">, MetaVarName<"<symbol>">,
120162
HelpText<"Use wrapper functions for symbol">;
121163

122-
def z : JoinedOrSeparate<["-"], "z">, MetaVarName<"<option>">,
164+
def z: JS<"z">, MetaVarName<"<option>">,
123165
HelpText<"Linker option extensions">;
124166

125167
// Aliases
126-
def alias_Bdynamic_call_shared: Flag<["-"], "call_shared">, Alias<Bdynamic>;
127-
def alias_Bdynamic_dy: Flag<["-"], "dy">, Alias<Bdynamic>;
128-
def alias_Bstatic_dn: Flag<["-"], "dn">, Alias<Bstatic>;
129-
def alias_Bstatic_non_shared: Flag<["-"], "non_shared">, Alias<Bstatic>;
130-
def alias_Bstatic_static: Flag<["-"], "static">, Alias<Bstatic>;
131-
def alias_L__library_path : Joined<["--"], "library-path=">, Alias<L>;
132-
def alias_discard_all_x: Flag<["-"], "x">, Alias<discard_all>;
133-
def alias_discard_locals_X: Flag<["-"], "X">, Alias<discard_locals>;
134-
def alias_dynamic_list: Joined<["--", "-"], "dynamic-list=">, Alias<dynamic_list>;
135-
def alias_entry_e : JoinedOrSeparate<["-"], "e">, Alias<entry>;
136-
def alias_export_dynamic_E: Flag<["-"], "E">, Alias<export_dynamic>;
137-
def alias_export_dynamic_symbol : Joined<["--", "-"], "export-dynamic-symbol=">,
138-
Alias<export_dynamic_symbol>;
139-
def alias_fini_fini : Joined<["-"], "fini=">, Alias<fini>;
140-
def alias_hash_style_hash_style : Joined<["--", "-"], "hash-style=">, Alias<hash_style>;
141-
def alias_init_init : Joined<["-"], "init=">, Alias<init>;
142-
def alias_l__library : Joined<["--"], "library=">, Alias<l>;
143-
def alias_o_output : Joined<["--"], "output=">, Alias<o>;
144-
def alias_pie_pic_executable: Flag<["--"], "pic-executable">, Alias<pie>;
145-
def alias_relocatable_r : Flag<["-"], "r">, Alias<relocatable>;
146-
def alias_rpath_R : Joined<["-"], "R">, Alias<rpath>;
147-
def alias_rpath_rpath : Joined<["-"], "rpath=">, Alias<rpath>;
148-
def alias_script_T : JoinedOrSeparate<["-"], "T">, Alias<script>;
149-
def alias_shared_Bshareable : Flag<["-"], "Bshareable">, Alias<shared>;
150-
def alias_soname_h : JoinedOrSeparate<["-"], "h">, Alias<soname>;
151-
def alias_soname_soname : Separate<["-"], "soname">, Alias<soname>;
152-
def alias_strip_all: Flag<["-"], "s">, Alias<strip_all>;
153-
def alias_strip_debug_S: Flag<["-"], "S">, Alias<strip_debug>;
154-
def alias_trace : Flag<["-"], "t">, Alias<trace>;
155-
def alias_undefined_u : JoinedOrSeparate<["-"], "u">, Alias<undefined>;
156-
def alias_wrap_wrap : Joined<["--", "-"], "wrap=">, Alias<wrap>;
168+
def alias_Bdynamic_call_shared: F<"call_shared">, Alias<Bdynamic>;
169+
def alias_Bdynamic_dy: F<"dy">, Alias<Bdynamic>;
170+
def alias_Bstatic_dn: F<"dn">, Alias<Bstatic>;
171+
def alias_Bstatic_non_shared: F<"non_shared">, Alias<Bstatic>;
172+
def alias_Bstatic_static: F<"static">, Alias<Bstatic>;
173+
def alias_L__library_path: J<"library-path=">, Alias<L>;
174+
def alias_discard_all_x: F<"x">, Alias<discard_all>;
175+
def alias_discard_locals_X: F<"X">, Alias<discard_locals>;
176+
def alias_dynamic_list: J<"dynamic-list=">, Alias<dynamic_list>;
177+
def alias_entry_e: JS<"e">, Alias<entry>;
178+
def alias_export_dynamic_E: F<"E">, Alias<export_dynamic>;
179+
def alias_export_dynamic_symbol: J<"export-dynamic-symbol=">,
180+
Alias<export_dynamic_symbol>;
181+
def alias_fini_fini: J<"fini=">, Alias<fini>;
182+
def alias_hash_style_hash_style: J<"hash-style=">, Alias<hash_style>;
183+
def alias_init_init: J<"init=">, Alias<init>;
184+
def alias_l__library: J<"library=">, Alias<l>;
185+
def alias_o_output: Joined<["--"], "output=">, Alias<o>;
186+
def alias_pie_pic_executable: F<"pic-executable">, Alias<pie>;
187+
def alias_relocatable_r: F<"r">, Alias<relocatable>;
188+
def alias_rpath_R: J<"R">, Alias<rpath>;
189+
def alias_rpath_rpath: J<"rpath=">, Alias<rpath>;
190+
def alias_script_T: JS<"T">, Alias<script>;
191+
def alias_shared_Bshareable: F<"Bshareable">, Alias<shared>;
192+
def alias_soname_h: JS<"h">, Alias<soname>;
193+
def alias_soname_soname: S<"soname">, Alias<soname>;
194+
def alias_strip_all: F<"s">, Alias<strip_all>;
195+
def alias_strip_debug_S: F<"S">, Alias<strip_debug>;
196+
def alias_trace: F<"t">, Alias<trace>;
197+
def alias_undefined_u: JoinedOrSeparate<["-"], "u">, Alias<undefined>;
198+
def alias_wrap_wrap: J<"wrap=">, Alias<wrap>;
157199

158200
// Our symbol resolution algorithm handles symbols in archive files differently
159201
// than traditional linkers, so we don't need --start-group and --end-group.
160202
// These options are recongized for compatibility but ignored.
161-
def end_group : Flag<["--"], "end-group">;
162-
def end_group_paren: Flag<["-"], ")">;
163-
def start_group : Flag<["--"], "start-group">;
164-
def start_group_paren: Flag<["-"], "(">;
203+
def end_group: F<"end-group">;
204+
def end_group_paren: F<")">;
205+
def start_group: F<"start-group">;
206+
def start_group_paren: F<"(">;
165207

166208
// Ignore LTO plugin-related options.
167209
// clang -flto passes -plugin and -plugin-opt to the linker. This is required
@@ -170,46 +212,45 @@ def start_group_paren: Flag<["-"], "(">;
170212
// just ignore the option on lld side as it's easier. In fact, the linker could
171213
// be called 'ld' and understanding which linker is used would require parsing of
172214
// --version output.
173-
def plugin : Separate<["--", "-"], "plugin">;
174-
def plugin_eq : Joined<["--", "-"], "plugin=">;
175-
def plugin_opt : Separate<["--", "-"], "plugin-opt">;
176-
def plugin_opt_eq : Joined<["--", "-"], "plugin-opt=">;
215+
def plugin: S<"plugin">;
216+
def plugin_eq: J<"plugin=">;
217+
def plugin_opt: S<"plugin-opt">;
218+
def plugin_opt_eq: J<"plugin-opt=">;
177219

178220
// Options listed below are silently ignored for now for compatibility.
179-
class Ignore<string name>: Flag<["-", "--"], name>;
180-
181-
def allow_shlib_undefined : Ignore<"allow-shlib-undefined">;
182-
def define_common : Ignore<"define-common">;
183-
def detect_odr_violations : Ignore<"detect-odr-violations">;
184-
def fatal_warnings : Ignore<"fatal-warnings">;
185-
def no_add_needed : Ignore<"no-add-needed">;
186-
def no_allow_shlib_undefined : Ignore<"no-allow-shlib-undefined">;
187-
def no_copy_dt_needed_entries : Ignore<"no-copy-dt-needed-entries">, Alias<no_add_needed>;
188-
def no_dynamic_linker : Ignore<"no-dynamic-linker">;
189-
def no_fatal_warnings : Ignore<"no-fatal-warnings">;
190-
def no_mmap_output_file : Ignore<"no-mmap-output-file">;
191-
def no_undefined_version : Ignore<"no-undefined-version">;
192-
def no_warn_common : Ignore<"no-warn-common">;
193-
def no_warn_mismatch : Ignore<"no-warn-mismatch">;
194-
def rpath_link : Separate<["--", "-"], "rpath-link">;
195-
def rpath_link_eq : Joined<["--", "-"], "rpath-link=">;
196-
def warn_execstack : Ignore<"warn-execstack">;
197-
def warn_shared_textrel : Ignore<"warn-shared-textrel">;
198-
def G : Separate<["-"], "G">;
221+
def allow_shlib_undefined: F<"allow-shlib-undefined">;
222+
def define_common: F<"define-common">;
223+
def detect_odr_violations: F<"detect-odr-violations">;
224+
def fatal_warnings: F<"fatal-warnings">;
225+
def no_add_needed: F<"no-add-needed">;
226+
def no_allow_shlib_undefined: F<"no-allow-shlib-undefined">;
227+
def no_copy_dt_needed_entries: F<"no-copy-dt-needed-entries">,
228+
Alias<no_add_needed>;
229+
def no_dynamic_linker: F<"no-dynamic-linker">;
230+
def no_fatal_warnings: F<"no-fatal-warnings">;
231+
def no_mmap_output_file: F<"no-mmap-output-file">;
232+
def no_undefined_version: F<"no-undefined-version">;
233+
def no_warn_common: F<"no-warn-common">;
234+
def no_warn_mismatch: F<"no-warn-mismatch">;
235+
def rpath_link: S<"rpath-link">;
236+
def rpath_link_eq: J<"rpath-link=">;
237+
def warn_execstack: F<"warn-execstack">;
238+
def warn_shared_textrel: F<"warn-shared-textrel">;
239+
def G: S<"G">;
199240

200241
// Aliases for ignored options
201-
def alias_define_common_d : Ignore<"d">, Alias<define_common>;
202-
def alias_define_common_dc : Ignore<"dc">, Alias<define_common>;
203-
def alias_define_common_dp : Ignore<"dp">, Alias<define_common>;
204-
def alias_version_script_version_script : Joined<["--"], "version-script=">, Alias<version_script>;
242+
def alias_define_common_d: F<"d">, Alias<define_common>;
243+
def alias_define_common_dc: F<"dc">, Alias<define_common>;
244+
def alias_define_common_dp: F<"dp">, Alias<define_common>;
245+
def alias_version_script_version_script: J<"version-script=">,
246+
Alias<version_script>;
205247

206248
// LTO-related options.
207-
def lto_jobs : Joined<["--"], "lto-jobs=">,
208-
HelpText<"Number of threads to run codegen">;
209-
def lto_aa_pipeline : Joined<["--"], "lto-aa-pipeline=">,
249+
def lto_jobs: J<"lto-jobs=">, HelpText<"Number of threads to run codegen">;
250+
def lto_aa_pipeline: J<"lto-aa-pipeline=">,
210251
HelpText<"AA pipeline to run during LTO. Used in conjunction with -lto-newpm-passes">;
211-
def lto_newpm_passes : Joined<["--"], "lto-newpm-passes=">,
252+
def lto_newpm_passes: J<"lto-newpm-passes=">,
212253
HelpText<"Passes to run during LTO">;
213-
def disable_verify : Flag<["-"], "disable-verify">;
214-
def mllvm : Separate<["-"], "mllvm">;
215-
def save_temps : Flag<["-"], "save-temps">;
254+
def disable_verify: F<"disable-verify">;
255+
def mllvm: S<"mllvm">;
256+
def save_temps: F<"save-temps">;

0 commit comments

Comments
 (0)
Please sign in to comment.