summaryrefslogtreecommitdiff
path: root/lld/wasm/Driver.cpp
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2018-05-10 18:23:51 +0000
committerSam Clegg <sbc@chromium.org>2018-05-10 18:23:51 +0000
commit6ea074c2c4b88344d185ada6d184b80bfd036667 (patch)
tree15eea9d339040ac39e174ceea3cc3110b6f79cbc /lld/wasm/Driver.cpp
parent2c6285cc26202cd63479d719236b14a7d790fdbb (diff)
[WebAssembly] Add a flag to control merging data segments
Merging data segments produces smaller code sizes because each segment has some boilerplate. Therefore, merging data segments is generally the right approach, especially with wasm where binaries are typically delivered over the network. However, when analyzing wasm binaries, it can be helpful to get a conservative picture of which functions are using which data segments[0]. Perhaps there is a large data segment that you didn't expect to be included in the wasm, introduced by some library you're using, and you'd like to know which library it was. In this scenario, merging data segments only makes the analysis worse. Alternatively, perhaps you will remove some dead functions by-hand[1] that can't be statically proven dead by the compiler or lld, and removing these functions might make some data garbage collect-able, and you'd like to run `--gc-sections` again so that this now-unused data can be collected. If the segments were originally merged, then a single use of the merged data segment will entrench all of the data. [0] https://github.com/rustwasm/twiggy [1] https://github.com/fitzgen/wasm-snip Patch by Nick Fitzgerald! Differential Revision: https://reviews.llvm.org/D46417
Diffstat (limited to 'lld/wasm/Driver.cpp')
-rw-r--r--lld/wasm/Driver.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 125a75a6e49..18dcde1dfe3 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -292,6 +292,9 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
Config->Relocatable = Args.hasArg(OPT_relocatable);
Config->GcSections =
Args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, !Config->Relocatable);
+ Config->MergeDataSegments =
+ Args.hasFlag(OPT_merge_data_segments, OPT_no_merge_data_segments,
+ !Config->Relocatable);
Config->PrintGcSections =
Args.hasFlag(OPT_print_gc_sections, OPT_no_print_gc_sections, false);
Config->SearchPaths = args::getStrings(Args, OPT_L);