1; RUN: llc -filetype=obj %s -o %t.o 2; RUN: yaml2obj %S/Inputs/globals.yaml -o %t_globals.o 3; RUN: wasm-ld -print-gc-sections -o %t1.wasm %t.o %t_globals.o | \ 4; RUN: FileCheck %s -check-prefix=PRINT-GC 5; PRINT-GC: removing unused section {{.*}}:(unused_function) 6; PRINT-GC-NOT: removing unused section {{.*}}:(used_function) 7; PRINT-GC: removing unused section {{.*}}:(.data.unused_data) 8; PRINT-GC-NOT: removing unused section {{.*}}:(.data.used_data) 9; PRINT-GC: removing unused section {{.*}}:(unused_global) 10; PRINT-GC-NOT: removing unused section {{.*}}:(used_global) 11 12target triple = "wasm32-unknown-unknown" 13 14@unused_data = hidden global i64 1, align 4 15@used_data = hidden global i32 2, align 4 16 17define hidden i64 @unused_function(i64 %arg) { 18 %1 = load i64, i64* @unused_data, align 4 19 ret i64 %1 20} 21 22define hidden i32 @used_function() { 23 %1 = load i32, i32* @used_data, align 4 24 ret i32 %1 25} 26 27declare i64 @use_global() 28 29define hidden void @_start() { 30entry: 31 call i32 @used_function() 32 call i64 @use_global() 33 ret void 34} 35 36; RUN: obj2yaml %t1.wasm | FileCheck %s 37 38; CHECK: - Type: TYPE 39; CHECK-NEXT: Signatures: 40; CHECK-NEXT: - Index: 0 41; CHECK-NEXT: ParamTypes: [] 42; CHECK-NEXT: ReturnTypes: 43; CHECK-NEXT: - I32 44; CHECK-NEXT: - Index: 1 45; CHECK-NEXT: ParamTypes: [] 46; CHECK-NEXT: ReturnTypes: [] 47; CHECK-NEXT: - Index: 2 48; CHECK-NEXT: ParamTypes: [] 49; CHECK-NEXT: ReturnTypes: 50; CHECK-NEXT: - I64 51; CHECK-NEXT: - Type: FUNCTION 52 53; CHECK: - Type: GLOBAL 54; CHECK-NEXT: Globals: 55; CHECK-NEXT: - Index: 0 56; CHECK-NEXT: Type: I32 57; CHECK-NEXT: Mutable: true 58; CHECK-NEXT: InitExpr: 59; CHECK-NEXT: Opcode: I32_CONST 60; CHECK-NEXT: Value: 66576 61; CHECK-NEXT: - Index: 1 62; CHECK-NEXT: Type: I64 63; CHECK-NEXT: Mutable: true 64; CHECK-NEXT: InitExpr: 65; CHECK-NEXT: Opcode: I64_CONST 66; CHECK-NEXT: Value: 456 67 68; CHECK: - Type: DATA 69; CHECK-NEXT: Segments: 70; CHECK-NEXT: - SectionOffset: 7 71; CHECK-NEXT: InitFlags: 0 72; CHECK-NEXT: Offset: 73; CHECK-NEXT: Opcode: I32_CONST 74; CHECK-NEXT: Value: 1024 75; CHECK-NEXT: Content: '02000000' 76; CHECK-NEXT: - Type: CUSTOM 77; CHECK-NEXT: Name: name 78; CHECK-NEXT: FunctionNames: 79; CHECK-NEXT: - Index: 0 80; CHECK-NEXT: Name: used_function 81; CHECK-NEXT: - Index: 1 82; CHECK-NEXT: Name: _start 83; CHECK-NEXT: - Index: 2 84; CHECK-NEXT: Name: use_global 85; CHECK-NEXT: GlobalNames: 86; CHECK-NEXT: - Index: 0 87; CHECK-NEXT: Name: __stack_pointer 88; CHECK-NEXT: - Index: 1 89; CHECK-NEXT: Name: used_global 90; CHECK-NEXT: ... 91 92; RUN: wasm-ld -print-gc-sections --no-gc-sections -o %t1.no-gc.wasm \ 93; RUN: %t.o %t_globals.o 94; RUN: obj2yaml %t1.no-gc.wasm | FileCheck %s -check-prefix=NO-GC 95 96; NO-GC: - Type: TYPE 97; NO-GC-NEXT: Signatures: 98; NO-GC-NEXT: - Index: 0 99; NO-GC-NEXT: ParamTypes: [] 100; NO-GC-NEXT: ReturnTypes: [] 101; NO-GC-NEXT: - Index: 1 102; NO-GC-NEXT: ParamTypes: 103; NO-GC-NEXT: - I64 104; NO-GC-NEXT: ReturnTypes: 105; NO-GC-NEXT: - I64 106; NO-GC-NEXT: - Index: 2 107; NO-GC-NEXT: ParamTypes: [] 108; NO-GC-NEXT: ReturnTypes: 109; NO-GC-NEXT: - I32 110; NO-GC-NEXT: - Index: 3 111; NO-GC-NEXT: ParamTypes: [] 112; NO-GC-NEXT: ReturnTypes: 113; NO-GC-NEXT: - I64 114; NO-GC-NEXT: - Type: FUNCTION 115 116; NO-GC: - Type: GLOBAL 117; NO-GC-NEXT: Globals: 118; NO-GC-NEXT: - Index: 0 119; NO-GC-NEXT: Type: I32 120; NO-GC-NEXT: Mutable: true 121; NO-GC-NEXT: InitExpr: 122; NO-GC-NEXT: Opcode: I32_CONST 123; NO-GC-NEXT: Value: 66576 124; NO-GC-NEXT: - Index: 1 125; NO-GC-NEXT: Type: I64 126; NO-GC-NEXT: Mutable: true 127; NO-GC-NEXT: InitExpr: 128; NO-GC-NEXT: Opcode: I64_CONST 129; NO-GC-NEXT: Value: 123 130; NO-GC-NEXT: - Index: 2 131; NO-GC-NEXT: Type: I64 132; NO-GC-NEXT: Mutable: true 133; NO-GC-NEXT: InitExpr: 134; NO-GC-NEXT: Opcode: I64_CONST 135; NO-GC-NEXT: Value: 456 136 137; NO-GC: - Type: DATA 138; NO-GC-NEXT: Segments: 139; NO-GC-NEXT: - SectionOffset: 7 140; NO-GC-NEXT: InitFlags: 0 141; NO-GC-NEXT: Offset: 142; NO-GC-NEXT: Opcode: I32_CONST 143; NO-GC-NEXT: Value: 1024 144; NO-GC-NEXT: Content: '010000000000000002000000' 145; NO-GC-NEXT: - Type: CUSTOM 146; NO-GC-NEXT: Name: name 147; NO-GC-NEXT: FunctionNames: 148; NO-GC-NEXT: - Index: 0 149; NO-GC-NEXT: Name: __wasm_call_ctors 150; NO-GC-NEXT: - Index: 1 151; NO-GC-NEXT: Name: unused_function 152; NO-GC-NEXT: - Index: 2 153; NO-GC-NEXT: Name: used_function 154; NO-GC-NEXT: - Index: 3 155; NO-GC-NEXT: Name: _start 156; NO-GC-NEXT: - Index: 4 157; NO-GC-NEXT: Name: use_global 158; NO-GC-NEXT: GlobalNames: 159; NO-GC-NEXT: - Index: 0 160; NO-GC-NEXT: Name: __stack_pointer 161; NO-GC-NEXT: - Index: 1 162; NO-GC-NEXT: Name: unused_global 163; NO-GC-NEXT: - Index: 2 164; NO-GC-NEXT: Name: used_global 165; NO-GC-NEXT: ... 166 167; RUN: not wasm-ld --gc-sections --relocatable -o %t1.no-gc.wasm %t.o 2>&1 | FileCheck %s -check-prefix=CHECK-ERROR 168; CHECK-ERROR: error: -r and --gc-sections may not be used together 169