Yuta Saito ba3c1f9ce3
[WebAssembly] Add segment RETAIN flag to support private retained data (#81539)
In WebAssembly, we have `WASM_SYMBOL_NO_STRIP` symbol flag to mark the
referenced content as retained. However, the flag is not enough to
express retained data that is not referenced by any symbol. This patch
adds a new segment flag`WASM_SEG_FLAG_RETAIN` to support "private"
linkage data that is retained by llvm.used.

This kind of data that is not referenced but must be retained is usually
used with encapsulation symbols (__start/__stop). Swift runtime uses
this technique and depends on the fact "all metadata sections in live
objects are retained", which was not guaranteed with `--gc-sections`
before this patch.

This is a revised version of https://reviews.llvm.org/D126950 (has been
reverted) based on @MaskRay's comments
2024-02-21 03:35:36 +09:00

23 lines
691 B
LLVM

; 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"