This repository has been archived by the owner on Apr 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@332013 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
5 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
target triple = "wasm32-unknown-unknown" | ||
|
||
@a = hidden global [6 x i8] c"hello\00", align 1 | ||
@b = hidden global [8 x i8] c"goodbye\00", align 1 | ||
@c = hidden global [9 x i8] c"whatever\00", align 1 | ||
@d = hidden global i32 42, align 4 | ||
|
||
; RUN: llc -filetype=obj %s -o %t.data-segment-merging.o | ||
|
||
; RUN: wasm-ld -no-gc-sections --allow-undefined -o %t.merged.wasm %t.data-segment-merging.o | ||
; RUN: obj2yaml %t.merged.wasm | FileCheck %s --check-prefix=MERGE | ||
; MERGE: - Type: DATA | ||
; MERGE-NEXT: Segments: | ||
; MERGE-NEXT: - SectionOffset: 7 | ||
; MERGE-NEXT: MemoryIndex: 0 | ||
; MERGE-NEXT: Offset: | ||
; MERGE-NEXT: Opcode: I32_CONST | ||
; MERGE-NEXT: Value: 1024 | ||
; MERGE-NEXT: Content: 68656C6C6F00676F6F6462796500776861746576657200002A000000 | ||
|
||
; RUN: wasm-ld -no-gc-sections --allow-undefined --no-merge-data-segments -o %t.separate.wasm %t.data-segment-merging.o | ||
; RUN: obj2yaml %t.separate.wasm | FileCheck %s --check-prefix=SEPARATE | ||
; SEPARATE: - Type: DATA | ||
; SEPARATE-NEXT: Segments: | ||
; SEPARATE-NEXT: - SectionOffset: 7 | ||
; SEPARATE-NEXT: MemoryIndex: 0 | ||
; SEPARATE-NEXT: Offset: | ||
; SEPARATE-NEXT: Opcode: I32_CONST | ||
; SEPARATE-NEXT: Value: 1024 | ||
; SEPARATE-NEXT: Content: 68656C6C6F00 | ||
; SEPARATE-NEXT: - SectionOffset: 19 | ||
; SEPARATE-NEXT: MemoryIndex: 0 | ||
; SEPARATE-NEXT: Offset: | ||
; SEPARATE-NEXT: Opcode: I32_CONST | ||
; SEPARATE-NEXT: Value: 1030 | ||
; SEPARATE-NEXT: Content: 676F6F6462796500 | ||
; SEPARATE-NEXT: - SectionOffset: 33 | ||
; SEPARATE-NEXT: MemoryIndex: 0 | ||
; SEPARATE-NEXT: Offset: | ||
; SEPARATE-NEXT: Opcode: I32_CONST | ||
; SEPARATE-NEXT: Value: 1038 | ||
; SEPARATE-NEXT: Content: '776861746576657200' | ||
; SEPARATE-NEXT: - SectionOffset: 48 | ||
; SEPARATE-NEXT: MemoryIndex: 0 | ||
; SEPARATE-NEXT: Offset: | ||
; SEPARATE-NEXT: Opcode: I32_CONST | ||
; SEPARATE-NEXT: Value: 1048 | ||
; SEPARATE-NEXT: Content: 2A000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters