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 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebAssembly] Add support for --gc-sections
In this initial version we only GC symbols with `hidden` visibility since other symbols we export to the embedder. We could potentially modify this the future and only use symbols explicitly passed via `--export` as GC roots. This version of the code only does GC of data and code. GC for the types section is coming soon. Differential Revision: https://reviews.llvm.org/D42511 git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@323842 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
17 changed files
with
269 additions
and
21 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
; RUN: llc -filetype=obj %s -o %t.o | ||
; RUN: lld -flavor wasm -print-gc-sections -o %t1.wasm %t.o | FileCheck %s -check-prefix=PRINT-GC | ||
; PRINT-GC: removing unused section 'unused_function' in file '{{.*}}' | ||
; PRINT-GC-NOT: removing unused section 'used_function' in file '{{.*}}' | ||
; PRINT-GC: removing unused section '.data.unused_data' in file '{{.*}}' | ||
; PRINT-GC-NOT: removing unused section '.data.used_data' in file '{{.*}}' | ||
|
||
target triple = "wasm32-unknown-unknown-wasm" | ||
|
||
@unused_data = hidden global i32 1, align 4 | ||
@used_data = hidden global i32 2, align 4 | ||
|
||
define hidden i32 @unused_function() { | ||
%1 = load i32, i32* @unused_data, align 4 | ||
ret i32 %1 | ||
} | ||
|
||
define hidden i32 @used_function() { | ||
%1 = load i32, i32* @used_data, align 4 | ||
ret i32 %1 | ||
} | ||
|
||
define hidden void @_start() { | ||
entry: | ||
call i32 @used_function() | ||
ret void | ||
} | ||
|
||
; RUN: obj2yaml %t1.wasm | FileCheck %s | ||
; CHECK: - Type: DATA | ||
; CHECK-NEXT: Segments: | ||
; CHECK-NEXT: - SectionOffset: 7 | ||
; CHECK-NEXT: MemoryIndex: 0 | ||
; CHECK-NEXT: Offset: | ||
; CHECK-NEXT: Opcode: I32_CONST | ||
; CHECK-NEXT: Value: 1024 | ||
; CHECK-NEXT: Content: '02000000' | ||
; CHECK-NEXT: - Type: CUSTOM | ||
; CHECK-NEXT: Name: linking | ||
; CHECK-NEXT: DataSize: 4 | ||
; CHECK-NEXT: - Type: CUSTOM | ||
; CHECK-NEXT: Name: name | ||
; CHECK-NEXT: FunctionNames: | ||
; CHECK-NEXT: - Index: 0 | ||
; CHECK-NEXT: Name: used_function | ||
; CHECK-NEXT: - Index: 1 | ||
; CHECK-NEXT: Name: _start | ||
; CHECK-NEXT: - Index: 2 | ||
; CHECK-NEXT: Name: __wasm_call_ctors | ||
; CHECK-NEXT: ... | ||
|
||
; RUN: lld -flavor wasm -print-gc-sections --no-gc-sections -o %t1.no-gc.wasm %t.o | ||
; RUN: obj2yaml %t1.no-gc.wasm | FileCheck %s -check-prefix=NO-GC | ||
; NO-GC: - Type: DATA | ||
; NO-GC-NEXT: Segments: | ||
; NO-GC-NEXT: - SectionOffset: 7 | ||
; NO-GC-NEXT: MemoryIndex: 0 | ||
; NO-GC-NEXT: Offset: | ||
; NO-GC-NEXT: Opcode: I32_CONST | ||
; NO-GC-NEXT: Value: 1024 | ||
; NO-GC-NEXT: Content: '0100000002000000' | ||
; NO-GC-NEXT: - Type: CUSTOM | ||
; NO-GC-NEXT: Name: linking | ||
; NO-GC-NEXT: DataSize: 8 | ||
; NO-GC-NEXT: - Type: CUSTOM | ||
; NO-GC-NEXT: Name: name | ||
; NO-GC-NEXT: FunctionNames: | ||
; NO-GC-NEXT: - Index: 0 | ||
; NO-GC-NEXT: Name: unused_function | ||
; NO-GC-NEXT: - Index: 1 | ||
; NO-GC-NEXT: Name: used_function | ||
; NO-GC-NEXT: - Index: 2 | ||
; NO-GC-NEXT: Name: _start | ||
; NO-GC-NEXT: - Index: 3 | ||
; NO-GC-NEXT: Name: __wasm_call_ctors | ||
; NO-GC-NEXT: ... | ||
|
||
; RUN: not lld -flavor wasm --gc-sections --relocatable -o %t1.no-gc.wasm %t.o 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR | ||
; CHECK-ERROR: lld: error: -r and --gc-sections may not be used together |
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
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
Oops, something went wrong.