[lld] [llvm] [WebAssembly] Add segment NO_STRIP flag to support private retained data (PR #81539)

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 12 14:20:29 PST 2024


================
@@ -0,0 +1,61 @@
+; RUN: split-file %s %t
+; RUN: llc -filetype=obj --mtriple=wasm32-unknown-unknown -o %t/main.o %t/main.ll
+; RUN: llc -filetype=obj --mtriple=wasm32-unknown-unknown -o %t/liba_x.o %t/liba_x.ll
+; RUN: llc -filetype=obj --mtriple=wasm32-unknown-unknown -o %t/liba_y.o %t/liba_y.ll
+; 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.ll
+
+ at greet_a = private constant [6 x i8] c"hello\00", align 1, section "greetings"
+ at weather_a = private constant [7 x i8] c"cloudy\00", align 1, section "weathers"
+ at llvm.used = appending global [2 x ptr] [ptr @greet_a, ptr @weather_a], section "llvm.metadata"
+
+declare void @grab_liba()
+define void @_start() {
+  call void @grab_liba()
+  ret void
+}
----------------
sbc100 wrote:

We've been trying to move all linker tests to `.s` (assembly) rather then `.ll` bitcode.   Can we write this in asm instead?

If you want to test that @llvm.used lowers to the new flag that testing should happen in llvm tests rather then wasm-ld tests.

https://github.com/llvm/llvm-project/pull/81539


More information about the llvm-commits mailing list