[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
llvm-svn: 332013
2018-05-11 02:23:51 +08:00
|
|
|
@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
|
|
|
|
|
2018-08-09 02:02:55 +08:00
|
|
|
@e = private constant [9 x i8] c"constant\00", align 1
|
|
|
|
@f = private constant i8 43, align 4
|
|
|
|
|
2020-12-01 06:00:34 +08:00
|
|
|
; RUN: llc --mtriple=wasm32-unknown-unknown -mattr=+bulk-memory,+atomics -filetype=obj %s -o %t.passive.o
|
|
|
|
; RUN: llc --mtriple=wasm64-unknown-unknown -mattr=+bulk-memory,+atomics -filetype=obj %s -o %t.passive64.o
|
|
|
|
; RUN: llc --mtriple=wasm32-unknown-unknown -filetype=obj %s -o %t.o
|
[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
llvm-svn: 332013
2018-05-11 02:23:51 +08:00
|
|
|
|
2019-07-04 06:04:54 +08:00
|
|
|
; RUN: wasm-ld -no-gc-sections --no-entry -o %t.merged.wasm %t.o
|
[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
llvm-svn: 332013
2018-05-11 02:23:51 +08:00
|
|
|
; RUN: obj2yaml %t.merged.wasm | FileCheck %s --check-prefix=MERGE
|
2019-04-20 07:40:36 +08:00
|
|
|
|
2019-07-04 06:04:54 +08:00
|
|
|
; MERGE-LABEL: - Type: DATA
|
|
|
|
; MERGE-NEXT: Segments:
|
|
|
|
; MERGE-NEXT: - SectionOffset: 7
|
|
|
|
; MERGE-NEXT: InitFlags: 0
|
|
|
|
; MERGE-NEXT: Offset:
|
2019-09-19 09:14:59 +08:00
|
|
|
; MERGE: Content: 636F6E7374616E74000000002B
|
|
|
|
; MERGE-NEXT: - SectionOffset: 26
|
2019-07-04 06:04:54 +08:00
|
|
|
; MERGE-NEXT: InitFlags: 0
|
|
|
|
; MERGE-NEXT: Offset:
|
2019-09-19 09:14:59 +08:00
|
|
|
; MERGE: Content: 68656C6C6F00676F6F6462796500776861746576657200002A000000
|
2019-07-04 06:04:54 +08:00
|
|
|
; MERGE-NEXT: - Type: CUSTOM
|
|
|
|
; MERGE-NEXT: Name: name
|
|
|
|
; MERGE-NEXT: FunctionNames:
|
|
|
|
; MERGE-NEXT: - Index: 0
|
|
|
|
; MERGE-NEXT: Name: __wasm_call_ctors
|
2020-11-19 13:38:23 +08:00
|
|
|
; MERGE-NEXT: GlobalNames:
|
|
|
|
; MERGE-NEXT: - Index: 0
|
|
|
|
; MERGE-NEXT: Name: __stack_pointer
|
2020-12-09 13:47:19 +08:00
|
|
|
; MERGE-NEXT: DataSegmentNames:
|
|
|
|
; MERGE-NEXT: - Index: 0
|
|
|
|
; MERGE-NEXT: Name: .rodata
|
[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
llvm-svn: 332013
2018-05-11 02:23:51 +08:00
|
|
|
|
2019-07-04 06:04:54 +08:00
|
|
|
; RUN: wasm-ld -no-gc-sections --no-entry --no-merge-data-segments -o %t.separate.wasm %t.o
|
[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
llvm-svn: 332013
2018-05-11 02:23:51 +08:00
|
|
|
; RUN: obj2yaml %t.separate.wasm | FileCheck %s --check-prefix=SEPARATE
|
2019-04-20 07:40:36 +08:00
|
|
|
|
|
|
|
; SEPARATE-NOT: DATACOUNT
|
2019-07-04 06:04:54 +08:00
|
|
|
; SEPARATE-LABEL: - Type: DATA
|
|
|
|
; SEPARATE-NEXT: Segments:
|
|
|
|
; SEPARATE-NEXT: - SectionOffset: 7
|
|
|
|
; SEPARATE-NEXT: InitFlags: 0
|
|
|
|
; SEPARATE-NEXT: Offset:
|
2019-09-19 09:14:59 +08:00
|
|
|
; SEPARATE: Content: 636F6E7374616E7400
|
|
|
|
; SEPARATE-NEXT: - SectionOffset: 22
|
2019-07-04 06:04:54 +08:00
|
|
|
; SEPARATE-NEXT: InitFlags: 0
|
|
|
|
; SEPARATE-NEXT: Offset:
|
2019-09-19 09:14:59 +08:00
|
|
|
; SEPARATE: Content: 2B
|
|
|
|
; SEPARATE-NEXT: - SectionOffset: 29
|
2019-07-04 06:04:54 +08:00
|
|
|
; SEPARATE-NEXT: InitFlags: 0
|
|
|
|
; SEPARATE-NEXT: Offset:
|
2019-09-19 09:14:59 +08:00
|
|
|
; SEPARATE: Content: 68656C6C6F00
|
|
|
|
; SEPARATE-NEXT: - SectionOffset: 41
|
2019-07-04 06:04:54 +08:00
|
|
|
; SEPARATE-NEXT: InitFlags: 0
|
|
|
|
; SEPARATE-NEXT: Offset:
|
2019-09-19 09:14:59 +08:00
|
|
|
; SEPARATE: Content: 676F6F6462796500
|
|
|
|
; SEPARATE-NEXT: - SectionOffset: 55
|
2019-07-04 06:04:54 +08:00
|
|
|
; SEPARATE-NEXT: InitFlags: 0
|
|
|
|
; SEPARATE-NEXT: Offset:
|
2019-09-19 09:14:59 +08:00
|
|
|
; SEPARATE: Content: '776861746576657200'
|
|
|
|
; SEPARATE-NEXT: - SectionOffset: 70
|
2019-07-04 06:04:54 +08:00
|
|
|
; SEPARATE-NEXT: InitFlags: 0
|
|
|
|
; SEPARATE-NEXT: Offset:
|
2019-09-19 09:14:59 +08:00
|
|
|
; SEPARATE: Content: 2A000000
|
2019-07-04 06:04:54 +08:00
|
|
|
; SEPARATE-NEXT: - Type: CUSTOM
|
|
|
|
; SEPARATE-NEXT: Name: name
|
|
|
|
; SEPARATE-NEXT: FunctionNames:
|
|
|
|
; SEPARATE-NEXT: - Index: 0
|
|
|
|
; SEPARATE-NEXT: Name: __wasm_call_ctors
|
2020-11-19 13:38:23 +08:00
|
|
|
; SEPARATE-NEXT: GlobalNames:
|
|
|
|
; SEPARATE-NEXT: - Index: 0
|
|
|
|
; SEPARATE-NEXT: Name: __stack_pointer
|
2020-12-09 13:47:19 +08:00
|
|
|
; SEPARATE-NEXT: DataSegmentNames:
|
|
|
|
; SEPARATE-NEXT: - Index: 0
|
|
|
|
; SEPARATE-NEXT: Name: .rodata
|
2019-07-04 06:04:54 +08:00
|
|
|
|
2019-09-05 03:50:39 +08:00
|
|
|
; RUN: wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 -o %t.merged.passive.wasm %t.passive.o
|
2019-07-04 06:04:54 +08:00
|
|
|
; RUN: obj2yaml %t.merged.passive.wasm | FileCheck %s --check-prefix=PASSIVE-MERGE
|
2020-12-01 06:00:34 +08:00
|
|
|
; RUN: wasm-ld -mwasm64 -no-gc-sections --no-entry --shared-memory --max-memory=131072 -o %t.merged.passive64.wasm %t.passive64.o
|
|
|
|
; RUN: obj2yaml %t.merged.passive64.wasm | FileCheck %s --check-prefix=PASSIVE-MERGE
|
2019-07-04 06:04:54 +08:00
|
|
|
|
|
|
|
; PASSIVE-MERGE-LABEL: - Type: DATACOUNT
|
|
|
|
; PASSIVE-MERGE-NEXT: Count: 2
|
|
|
|
; PASSIVE-MERGE-LABEL: - Type: DATA
|
|
|
|
; PASSIVE-MERGE-NEXT: Segments:
|
|
|
|
; PASSIVE-MERGE-NEXT: - SectionOffset: 3
|
|
|
|
; PASSIVE-MERGE-NEXT: InitFlags: 1
|
|
|
|
; PASSIVE-MERGE-NEXT: Content: 636F6E7374616E74000000002B
|
2019-09-19 09:14:59 +08:00
|
|
|
; PASSIVE-MERGE-NEXT: - SectionOffset: 18
|
|
|
|
; PASSIVE-MERGE-NEXT: InitFlags: 1
|
|
|
|
; PASSIVE-MERGE-NEXT: Content: 68656C6C6F00676F6F6462796500776861746576657200002A000000
|
2019-07-04 06:04:54 +08:00
|
|
|
; PASSIVE-MERGE-NEXT: - Type: CUSTOM
|
|
|
|
; PASSIVE-MERGE-NEXT: Name: name
|
|
|
|
; PASSIVE-MERGE-NEXT: FunctionNames:
|
|
|
|
; PASSIVE-MERGE-NEXT: - Index: 0
|
|
|
|
; PASSIVE-MERGE-NEXT: Name: __wasm_call_ctors
|
|
|
|
; PASSIVE-MERGE-NEXT: - Index: 1
|
2019-09-05 03:50:39 +08:00
|
|
|
; PASSIVE-MERGE-NEXT: Name: __wasm_init_tls
|
2020-12-10 23:40:48 +08:00
|
|
|
; PASSIVE-MERGE-NEXT: - Index: 2
|
|
|
|
; PASSIVE-MERGE-NEXT: Name: __wasm_init_memory
|
2019-07-04 06:04:54 +08:00
|
|
|
|
2019-09-05 03:50:39 +08:00
|
|
|
; RUN: wasm-ld -no-gc-sections --no-entry --shared-memory --max-memory=131072 -no-merge-data-segments -o %t.separate.passive.wasm %t.passive.o
|
2019-07-04 06:04:54 +08:00
|
|
|
; RUN: obj2yaml %t.separate.passive.wasm | FileCheck %s --check-prefix=PASSIVE-SEPARATE
|
2020-12-01 06:00:34 +08:00
|
|
|
; RUN: wasm-ld -mwasm64 -no-gc-sections --no-entry --shared-memory --max-memory=131072 -no-merge-data-segments -o %t.separate.passive64.wasm %t.passive64.o
|
|
|
|
; RUN: obj2yaml %t.separate.passive64.wasm | FileCheck %s --check-prefix=PASSIVE-SEPARATE
|
2019-07-04 06:04:54 +08:00
|
|
|
|
|
|
|
; PASSIVE-SEPARATE-LABEL: - Type: DATACOUNT
|
|
|
|
; PASSIVE-SEPARATE-NEXT: Count: 6
|
|
|
|
; PASSIVE-SEPARATE-LABEL: - Type: DATA
|
|
|
|
; PASSIVE-SEPARATE-NEXT: Segments:
|
|
|
|
; PASSIVE-SEPARATE-NEXT: - SectionOffset: 3
|
|
|
|
; PASSIVE-SEPARATE-NEXT: InitFlags: 1
|
2019-09-19 09:14:59 +08:00
|
|
|
; PASSIVE-SEPARATE-NEXT: Content: 636F6E7374616E7400
|
|
|
|
; PASSIVE-SEPARATE-NEXT: - SectionOffset: 14
|
|
|
|
; PASSIVE-SEPARATE-NEXT: InitFlags: 1
|
|
|
|
; PASSIVE-SEPARATE-NEXT: Content: 2B
|
|
|
|
; PASSIVE-SEPARATE-NEXT: - SectionOffset: 17
|
|
|
|
; PASSIVE-SEPARATE-NEXT: InitFlags: 1
|
2019-07-04 06:04:54 +08:00
|
|
|
; PASSIVE-SEPARATE-NEXT: Content: 68656C6C6F00
|
2019-09-19 09:14:59 +08:00
|
|
|
; PASSIVE-SEPARATE-NEXT: - SectionOffset: 25
|
2019-07-04 06:04:54 +08:00
|
|
|
; PASSIVE-SEPARATE-NEXT: InitFlags: 1
|
|
|
|
; PASSIVE-SEPARATE-NEXT: Content: 676F6F6462796500
|
2019-09-19 09:14:59 +08:00
|
|
|
; PASSIVE-SEPARATE-NEXT: - SectionOffset: 35
|
2019-07-04 06:04:54 +08:00
|
|
|
; PASSIVE-SEPARATE-NEXT: InitFlags: 1
|
|
|
|
; PASSIVE-SEPARATE-NEXT: Content: '776861746576657200'
|
2019-09-19 09:14:59 +08:00
|
|
|
; PASSIVE-SEPARATE-NEXT: - SectionOffset: 46
|
2019-07-04 06:04:54 +08:00
|
|
|
; PASSIVE-SEPARATE-NEXT: InitFlags: 1
|
|
|
|
; PASSIVE-SEPARATE-NEXT: Content: 2A000000
|
|
|
|
; PASSIVE-SEPARATE-NEXT: - Type: CUSTOM
|
|
|
|
; PASSIVE-SEPARATE-NEXT: Name: name
|
|
|
|
; PASSIVE-SEPARATE-NEXT: FunctionNames:
|
|
|
|
; PASSIVE-SEPARATE-NEXT: - Index: 0
|
|
|
|
; PASSIVE-SEPARATE-NEXT: Name: __wasm_call_ctors
|
|
|
|
; PASSIVE-SEPARATE-NEXT: - Index: 1
|
2019-09-05 03:50:39 +08:00
|
|
|
; PASSIVE-SEPARATE-NEXT: Name: __wasm_init_tls
|
2020-12-10 23:40:48 +08:00
|
|
|
; PASSIVE-SEPARATE-NEXT: - Index: 2
|
|
|
|
; PASSIVE-SEPARATE-NEXT: Name: __wasm_init_memory
|