-
Notifications
You must be signed in to change notification settings - Fork 14.2k
[WebAssembly] Add segment RETAIN flag to support private retained data #81539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# RUN: split-file %s %t | ||
# RUN: llvm-mc -filetype=obj --triple=wasm32-unknown-unknown -o %t/main.o %t/main.s | ||
# RUN: llvm-mc -filetype=obj --triple=wasm32-unknown-unknown -o %t/liba_x.o %t/liba_x.s | ||
# RUN: llvm-mc -filetype=obj --triple=wasm32-unknown-unknown -o %t/liba_y.o %t/liba_y.s | ||
# RUN: rm -f %t/liba.a | ||
# RUN: llvm-ar rcs %t/liba.a %t/liba_x.o %t/liba_y.o | ||
# RUN: wasm-ld %t/main.o %t/liba.a --gc-sections -o %t/main.wasm --print-gc-sections | FileCheck %s --check-prefix=GC | ||
# RUN: obj2yaml %t/main.wasm | FileCheck %s | ||
|
||
# --gc-sections should remove non-retained and unused "weathers" section from live object liba_x.o | ||
# GC: removing unused section {{.*}}/liba.a(liba_x.o):(weathers) | ||
# Should not remove retained "greetings" sections from live objects main.o and liba_x.o | ||
# GC-NOT: removing unused section %t/main.o:(greetings) | ||
# GC-NOT: removing unused section %t/liba_x.o:(greetings) | ||
|
||
# Note: All symbols are private so that they don't join the symbol table. | ||
|
||
#--- main.s | ||
.functype grab_liba () -> () | ||
.globl _start | ||
_start: | ||
.functype _start () -> () | ||
call grab_liba | ||
end_function | ||
|
||
.section greetings,"R",@ | ||
.asciz "hello" | ||
.section weathers,"R",@ | ||
.asciz "cloudy" | ||
|
||
#--- liba_x.s | ||
.globl grab_liba | ||
grab_liba: | ||
.functype grab_liba () -> () | ||
end_function | ||
|
||
.section greetings,"R",@ | ||
.asciz "world" | ||
.section weathers,"",@ | ||
.asciz "rainy" | ||
|
||
#--- liba_y.s | ||
.section greetings,"R",@ | ||
.asciz "bye" | ||
|
||
|
||
# "greetings" section | ||
# CHECK: - Type: DATA | ||
# CHECK: Segments: | ||
# CHECK: - SectionOffset: 7 | ||
# CHECK: InitFlags: 0 | ||
# CHECK: Offset: | ||
# CHECK: Opcode: I32_CONST | ||
# CHECK: Value: 1024 | ||
# CHECK: Content: 68656C6C6F00776F726C6400 | ||
# "weahters" section. | ||
# CHECK: - SectionOffset: 25 | ||
# CHECK: InitFlags: 0 | ||
# CHECK: Offset: | ||
# CHECK: Opcode: I32_CONST | ||
# CHECK: Value: 1036 | ||
# CHECK: Content: 636C6F75647900 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,8 @@ void MCSectionWasm::printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, | |
OS << 'S'; | ||
if (SegmentFlags & wasm::WASM_SEG_FLAG_TLS) | ||
OS << 'T'; | ||
if (SegmentFlags & wasm::WASM_SEG_FLAG_RETAIN) | ||
OS << 'R'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this match ELF? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, ELF has a similar flag named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we mirror that name and use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chose NO_STRIP to align with the existing symbol-level flag WASM_SYMBOL_NO_STRIP, but I don't have strong opinions here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like to mirror the ELF flag names and I like that that assembly format "R" mnemonic matches, but I don't feel strongly. @MaskRay WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the record, it looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on how |
||
|
||
OS << '"'; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
; RUN: llc < %s --mtriple=wasm32-unknown-unknown | FileCheck %s | ||
|
||
@llvm.used = appending global [ | ||
5 x ptr | ||
] [ | ||
ptr @ga, ptr @gb, ptr @gc, ptr @gd, ptr @ge | ||
], section "llvm.metadata" | ||
|
||
; CHECK: .section .data.ga,"R",@ | ||
@ga = global i32 42 | ||
; CHECK: .section .data.gb,"R",@ | ||
@gb = internal global i32 41 | ||
; CHECK: .section .data..Lgc,"R",@ | ||
@gc = private global i32 40 | ||
; CHECK: .section .rodata.gd,"R",@ | ||
@gd = constant i32 39 | ||
|
||
; All sections with the same explicit name are flagged as retained if a part of them is retained. | ||
; CHECK: .section dddd,"R",@ | ||
@ge = global i32 38, section "dddd" | ||
; CHECK: .section dddd,"R",@ | ||
@gg = global i32 37, section "dddd" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,69 @@ | ||
; RUN: llc -filetype=obj -wasm-keep-registers %s -o - | llvm-readobj --symbols - | FileCheck %s | ||
; RUN: llc < %s --mtriple=wasm32-unknown-unknown -filetype=obj -wasm-keep-registers -o - | obj2yaml - | FileCheck %s | ||
|
||
target triple = "wasm32-unknown-unknown" | ||
|
||
@llvm.used = appending global [1 x ptr] [ptr @foo], section "llvm.metadata" | ||
@llvm.used = appending global [5 x ptr] [ | ||
ptr @foo, ptr @gv0, ptr @gv1, ptr @gv2, ptr @gv3 | ||
], section "llvm.metadata" | ||
|
||
define i32 @foo() { | ||
entry: | ||
ret i32 0 | ||
} | ||
|
||
; CHECK: Symbols [ | ||
; CHECK-NEXT: Symbol { | ||
; CHECK-NEXT: Name: foo | ||
; CHECK-NEXT: Type: FUNCTION (0x0) | ||
; CHECK-NEXT: Flags [ (0x80) | ||
; CHECK-NEXT: NO_STRIP (0x80) | ||
; CHECK-NEXT: ] | ||
; CHECK-NEXT: ElementIndex: 0x0 | ||
; CHECK-NEXT: } | ||
; CHECK-NEXT: ] | ||
; externally visible GV has NO_STRIP/RETAIN in both symtab entry and segment info | ||
@gv0 = global i32 42 | ||
; internal GV has NO_STRIP/RETAIN in both symtab entry and segment info | ||
@gv1 = internal global i32 41 | ||
; private GV has RETAIN in segment info only (no symtab entry) | ||
@gv2 = private global i32 40 | ||
; explicit section names | ||
@gv3 = global i32 39, section "ddd.hello" | ||
@gv4.not.used = global i64 38, section "ddd.hello" | ||
|
||
; CHECK: SymbolTable: | ||
; CHECK-NEXT: - Index: 0 | ||
; CHECK-NEXT: Kind: FUNCTION | ||
; CHECK-NEXT: Name: foo | ||
; CHECK-NEXT: Flags: [ NO_STRIP ] | ||
; CHECK-NEXT: Function: 0 | ||
; CHECK-NEXT: - Index: 1 | ||
; CHECK-NEXT: Kind: DATA | ||
; CHECK-NEXT: Name: gv0 | ||
; CHECK-NEXT: Flags: [ NO_STRIP ] | ||
; CHECK-NEXT: Segment: 0 | ||
; CHECK-NEXT: Size: 4 | ||
; CHECK-NEXT: - Index: 2 | ||
; CHECK-NEXT: Kind: DATA | ||
; CHECK-NEXT: Name: gv1 | ||
; CHECK-NEXT: Flags: [ BINDING_LOCAL, NO_STRIP ] | ||
; CHECK-NEXT: Segment: 1 | ||
; CHECK-NEXT: Size: 4 | ||
; CHECK-NEXT: - Index: 3 | ||
; CHECK-NEXT: Kind: DATA | ||
; CHECK-NEXT: Name: gv3 | ||
; CHECK-NEXT: Flags: [ NO_STRIP ] | ||
; CHECK-NEXT: Segment: 3 | ||
; CHECK-NEXT: Size: 4 | ||
; CHECK-NEXT: - Index: 4 | ||
; CHECK-NEXT: Kind: DATA | ||
; CHECK-NEXT: Name: gv4.not.used | ||
; CHECK-NEXT: Flags: [ ] | ||
; CHECK-NEXT: Segment: 3 | ||
; CHECK-NEXT: Offset: 8 | ||
; CHECK-NEXT: Size: 8 | ||
; CHECK-NEXT: SegmentInfo: | ||
; CHECK-NEXT: - Index: 0 | ||
; CHECK-NEXT: Name: .data.gv0 | ||
; CHECK-NEXT: Alignment: 2 | ||
; CHECK-NEXT: Flags: [ RETAIN ] | ||
; CHECK-NEXT: - Index: 1 | ||
; CHECK-NEXT: Name: .data.gv1 | ||
; CHECK-NEXT: Alignment: 2 | ||
; CHECK-NEXT: Flags: [ RETAIN ] | ||
; CHECK-NEXT: - Index: 2 | ||
; CHECK-NEXT: Name: .data..Lgv2 | ||
; CHECK-NEXT: Alignment: 2 | ||
; CHECK-NEXT: Flags: [ RETAIN ] | ||
; CHECK-NEXT: - Index: 3 | ||
; CHECK-NEXT: Name: ddd.hello | ||
; CHECK-NEXT: Alignment: 3 | ||
; CHECK-NEXT: Flags: [ RETAIN ] |
Uh oh!
There was an error while loading. Please reload this page.