Index: wasm/Config.h
===================================================================
--- wasm/Config.h
+++ wasm/Config.h
@@ -25,7 +25,9 @@
bool AllowUndefined;
bool CheckSignatures;
bool Demangle;
+ bool GcSections;
bool ImportMemory;
+ bool PrintGcSections;
bool Relocatable;
bool StripAll;
bool StripDebug;
Index: wasm/Driver.cpp
===================================================================
--- wasm/Driver.cpp
+++ wasm/Driver.cpp
@@ -250,9 +250,14 @@
Config->CheckSignatures =
Args.hasFlag(OPT_check_signatures, OPT_no_check_signatures, false);
Config->Entry = getEntry(Args, Args.hasArg(OPT_relocatable) ? "" : "_start");
+ errorHandler().FatalWarnings =
+ Args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false);
+ Config->GcSections = Args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, false);
Config->ImportMemory = Args.hasArg(OPT_import_memory);
Config->OutputFile = Args.getLastArgValue(OPT_o);
Config->Relocatable = Args.hasArg(OPT_relocatable);
+ Config->PrintGcSections =
+ Args.hasFlag(OPT_print_gc_sections, OPT_no_print_gc_sections, false);
Config->SearchPaths = args::getStrings(Args, OPT_L);
Config->StripAll = Args.hasArg(OPT_strip_all);
Config->StripDebug = Args.hasArg(OPT_strip_debug);
@@ -274,13 +279,15 @@
if (!Args.hasArg(OPT_INPUT))
error("no input files");
- if (Config->Relocatable && !Config->Entry.empty())
- error("entry point specified for relocatable output file");
- if (Config->Relocatable && Args.hasArg(OPT_undefined))
- error("undefined symbols specified for relocatable output file");
-
Symbol *EntrySym = nullptr;
- if (!Config->Relocatable) {
+ if (Config->Relocatable) {
+ if (!Config->Entry.empty())
+ error("entry point specified for relocatable output file");
+ if (Config->GcSections)
+ error("-r and --gc-sections may not be used together");
+ if (Args.hasArg(OPT_undefined))
+ error("-r -and --undefined may not be used together");
+ } else {
static WasmSignature Signature = {{}, WASM_TYPE_NORESULT};
if (!Config->Entry.empty())
EntrySym = Symtab->addUndefinedFunction(Config->Entry, &Signature);
Index: wasm/Options.td
===================================================================
--- wasm/Options.td
+++ wasm/Options.td
@@ -11,6 +11,7 @@
def _eq: Joined<["--", "-"], name # "=">, Alias(NAME)>;
}
+// The follow flags are shared with the ELF linker
def L: JoinedOrSeparate<["-"], "L">, MetaVarName<"
">,
HelpText<"Add a directory to the library search path">;
@@ -20,7 +21,18 @@
def color_diagnostics_eq: J<"color-diagnostics=">,
HelpText<"Use colors in diagnostics">;
-// The follow flags are shared with the ELF linker
+def entry: S<"entry">, MetaVarName<"">,
+ HelpText<"Name of entry point symbol">;
+
+def error_limit: J<"error-limit=">,
+ HelpText<"Maximum number of errors to emit before stopping (0 = no limit)">;
+
+def fatal_warnings: F<"fatal-warnings">,
+ HelpText<"Treat warnings as errors">;
+
+def gc_sections: F<"gc-sections">,
+ HelpText<"Enable garbage collection of unused sections">;
+
def help: F<"help">, HelpText<"Print option help">;
def l: JoinedOrSeparate<["-"], "l">, MetaVarName<"">,
@@ -34,20 +46,19 @@
def no_color_diagnostics: F<"no-color-diagnostics">,
HelpText<"Do not use colors in diagnostics">;
-def no_check_signatures: F<"no-check-signatures">, HelpText<"Don't check function signatures">;
+def no_fatal_warnings: F<"no-fatal-warnings">;
-def o: JoinedOrSeparate<["-"], "o">, MetaVarName<"">,
- HelpText<"Path to file to write output">;
-
-def threads: F<"threads">, HelpText<"Run the linker multi-threaded">;
+def no_gc_sections: F<"no-gc-sections">,
+ HelpText<"Disable garbage collection of unused sections">;
-def check_signatures: F<"check-signatures">, HelpText<"Check function signatures">;
-
-def v: Flag<["-"], "v">, HelpText<"Display the version number">;
+def no_print_gc_sections: F<"no-print-gc-sections">,
+ HelpText<"Do not list removed unused sections">;
-def version: F<"version">, HelpText<"Display the version number and exit">;
+def o: JoinedOrSeparate<["-"], "o">, MetaVarName<"">,
+ HelpText<"Path to file to write output">;
-def verbose: F<"verbose">, HelpText<"Verbose mode">;
+def print_gc_sections: F<"print-gc-sections">,
+ HelpText<"List removed unused sections">;
def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">;
@@ -55,22 +66,23 @@
def strip_debug: F<"strip-debug">, HelpText<"Strip debugging information">;
+def threads: F<"threads">, HelpText<"Run the linker multi-threaded">;
+
+def v: Flag<["-"], "v">, HelpText<"Display the version number">;
+
defm undefined: Eq<"undefined">,
HelpText<"Force undefined symbol during linking">;
-def z: JoinedOrSeparate<["-"], "z">, MetaVarName<"