diff options
| author | Martin Storsjo <martin@martin.st> | 2017-11-15 08:18:20 +0000 |
|---|---|---|
| committer | Martin Storsjo <martin@martin.st> | 2017-11-15 08:18:20 +0000 |
| commit | b190fd2bb46c69f282fedef29de9c090513f016e (patch) | |
| tree | 08a362eba2486d48f80626939ea4cc230c268fec | |
| parent | e916868269c9f9182b1d3c3613237a56188f56f8 (diff) | |
| download | bcm5719-llvm-b190fd2bb46c69f282fedef29de9c090513f016e.tar.gz bcm5719-llvm-b190fd2bb46c69f282fedef29de9c090513f016e.zip | |
[MinGW] Implement the --[no-]gc-sections and --icf options
GNU ld doesn't seem to support --icf at all, but this was suggested
in D39885, and GNU gold seems to support it.
Differential Revision: https://reviews.llvm.org/D40019
llvm-svn: 318283
| -rw-r--r-- | lld/MinGW/Driver.cpp | 17 | ||||
| -rw-r--r-- | lld/MinGW/Options.td | 3 | ||||
| -rw-r--r-- | lld/test/MinGW/driver.test | 19 |
3 files changed, 39 insertions, 0 deletions
diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp index 3c7b26b9d51..ad5fa5c17b3 100644 --- a/lld/MinGW/Driver.cpp +++ b/lld/MinGW/Driver.cpp @@ -161,6 +161,23 @@ bool mingw::link(ArrayRef<const char *> ArgsArr, raw_ostream &Diag) { Add(Args.hasArg(OPT_dynamicbase) ? "-dynamicbase" : "-dynamicbase:no"); + if (Args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, false)) + Add("-opt:ref"); + else + Add("-opt:noref"); + + if (auto *A = Args.getLastArg(OPT_icf)) { + StringRef S = A->getValue(); + if (S == "all") + Add("-opt:icf"); + else if (S == "safe" || S == "none") + Add("-opt:noicf"); + else + error("unknown parameter: --icf=" + S); + } else { + Add("-opt:noicf"); + } + if (auto *A = Args.getLastArg(OPT_m)) { StringRef S = A->getValue(); if (S == "i386pe") diff --git a/lld/MinGW/Options.td b/lld/MinGW/Options.td index 7631b6ab34c..2e6dbe56b1d 100644 --- a/lld/MinGW/Options.td +++ b/lld/MinGW/Options.td @@ -11,6 +11,8 @@ def entry: S<"entry">, MetaVarName<"<entry>">, HelpText<"Name of entry point symbol">; def export_all_symbols: F<"export-all-symbols">, HelpText<"Export all symbols even if a def file or dllexport attributes are used">; +def gc_sections: F<"gc-sections">, HelpText<"Remove unused sections">; +def icf: J<"icf=">, HelpText<"Identical code folding">; def image_base: S<"image-base">, HelpText<"Base address of the program">; def l: JoinedOrSeparate<["-"], "l">, MetaVarName<"<libName>">, HelpText<"Root name of library to use">; @@ -19,6 +21,7 @@ def no_whole_archive: F<"no-whole-archive">, HelpText<"No longer include all object files for following archives">; def large_address_aware: Flag<["--"], "large-address-aware">, HelpText<"Enable large addresses">; +def no_gc_sections: F<"no-gc-sections">, HelpText<"Don't remove unused sections">; def o: JoinedOrSeparate<["-"], "o">, MetaVarName<"<path>">, HelpText<"Path to file to write output">; def out_implib: Separate<["--"], "out-implib">, HelpText<"Import library name">; diff --git a/lld/test/MinGW/driver.test b/lld/test/MinGW/driver.test index edf0c0bad1f..b363b6b095d 100644 --- a/lld/test/MinGW/driver.test +++ b/lld/test/MinGW/driver.test @@ -105,3 +105,22 @@ DYNAMICBASE: -dynamicbase - RUN: ld.lld -### -m i386pep foo.o --image-base 0x1230000 | FileCheck -check-prefix IMAGE-BASE %s RUN: ld.lld -### -m i386pep foo.o -image-base 0x1230000 | FileCheck -check-prefix IMAGE-BASE %s IMAGE-BASE: -base:0x1230000 + +RUN: ld.lld -### -m i386pep foo.o | FileCheck -check-prefix NO-GC-SECTIONS %s +RUN: ld.lld -### -m i386pep foo.o --gc-sections --no-gc-sections | FileCheck -check-prefix NO-GC-SECTIONS %s +NO-GC-SECTIONS: -opt:noref + +RUN: ld.lld -### -m i386pep foo.o --gc-sections | FileCheck -check-prefix GC-SECTIONS %s +RUN: ld.lld -### -m i386pep foo.o -gc-sections | FileCheck -check-prefix GC-SECTIONS %s +GC-SECTIONS: -opt:ref + +RUN: ld.lld -### -m i386pep foo.o | FileCheck -check-prefix ICF-NONE %s +RUN: ld.lld -### -m i386pep foo.o --icf=none | FileCheck -check-prefix ICF-NONE %s +RUN: ld.lld -### -m i386pep foo.o -icf=none | FileCheck -check-prefix ICF-NONE %s +RUN: ld.lld -### -m i386pep foo.o --icf=safe | FileCheck -check-prefix ICF-NONE %s +RUN: ld.lld -### -m i386pep foo.o -icf=safe | FileCheck -check-prefix ICF-NONE %s +ICF-NONE: -opt:noicf + +RUN: ld.lld -### -m i386pep foo.o --icf=all | FileCheck -check-prefix ICF %s +RUN: ld.lld -### -m i386pep foo.o -icf=all | FileCheck -check-prefix ICF %s +ICF: -opt:icf |

