295 lines · plain
1; RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/hello.s -o %t.hello.o2; RUN: llc -filetype=obj %s -o %t.o3; RUN: wasm-ld -r -o %t2.o %t.hello.o %t.o4; RUN: obj2yaml %t2.o | FileCheck %s5 6; Verify the resulting object can be used as linker input7; RUN: wasm-ld --allow-undefined -o %t.wasm %t2.o --export-table8 9target triple = "wasm32-unknown-unknown"10 11; Function Attrs: nounwind12define hidden i32 @my_func() local_unnamed_addr {13entry:14 %call = tail call i32 @foo_import()15 %call2 = tail call i32 @bar_import()16 ret i32 117}18 19declare i32 @foo_import() local_unnamed_addr20declare extern_weak i32 @bar_import() local_unnamed_addr21@data_import = external global i6422 23@func_addr1 = hidden global ptr @my_func, align 424@func_addr2 = hidden global ptr @foo_import, align 425@func_addr3 = hidden global ptr @bar_import, align 426@data_addr1 = hidden global ptr @data_import, align 827 28$func_comdat = comdat any29@data_comdat = weak_odr constant [3 x i8] c"abc", comdat($func_comdat)30define linkonce_odr i32 @func_comdat() comdat {31entry:32 ret i32 ptrtoint (ptr @data_comdat to i32)33}34 35; Test that __attribute__(used) (i.e NO_STRIP) is preserved in the relocated symbol table36@llvm.used = appending global [1 x ptr] [ptr @my_func], section "llvm.metadata"37 38define void @_start() {39 ret void40}41 42 43; CHECK: --- !WASM44; CHECK-NEXT: FileHeader:45; CHECK-NEXT: Version: 0x146; CHECK-NEXT: Sections:47; CHECK-NEXT: - Type: TYPE48; CHECK-NEXT: Signatures:49; CHECK-NEXT: - Index: 050; CHECK-NEXT: ParamTypes:51; CHECK-NEXT: - I3252; CHECK-NEXT: ReturnTypes: []53; CHECK-NEXT: - Index: 154; CHECK-NEXT: ParamTypes:55; CHECK-NEXT: ReturnTypes:56; CHECK-NEXT: - I3257; CHECK-NEXT: - Index: 258; CHECK-NEXT: ParamTypes:59; CHECK-NEXT: ReturnTypes: []60; CHECK-NEXT: - Type: IMPORT61; CHECK-NEXT: Imports:62; CHECK-NEXT: - Module: env63; CHECK-NEXT: Field: __indirect_function_table64; CHECK-NEXT: Kind: TABLE65; CHECK-NEXT: Table:66; CHECK-NEXT: Index: 067; CHECK-NEXT: ElemType: FUNCREF68; CHECK-NEXT: Limits:69; CHECK-NEXT: Minimum: 0x470; CHECK-NEXT: - Module: env71; CHECK-NEXT: Field: puts72; CHECK-NEXT: Kind: FUNCTION73; CHECK-NEXT: SigIndex: 074; CHECK-NEXT: - Module: env75; CHECK-NEXT: Field: foo_import76; CHECK-NEXT: Kind: FUNCTION77; CHECK-NEXT: SigIndex: 178; CHECK-NEXT: - Module: env79; CHECK-NEXT: Field: bar_import80; CHECK-NEXT: Kind: FUNCTION81; CHECK-NEXT: SigIndex: 182; CHECK-NEXT: - Type: FUNCTION83; CHECK-NEXT: FunctionTypes: [ 2, 1, 1, 2 ]84; CHECK-NEXT: - Type: MEMORY85; CHECK-NEXT: Memories:86; CHECK-NEXT: - Minimum: 0x187; CHECK-NEXT: - Type: ELEM88; CHECK-NEXT: Segments:89; CHECK-NEXT: - Offset:90; CHECK-NEXT: Opcode: I32_CONST91; CHECK-NEXT: Value: 192; CHECK-NEXT: Functions: [ 4, 1, 2 ]93; SHARED-NEXT: - Type: DATACOUNT94; SHARED-NEXT: Count: 695; CHECK-NEXT: - Type: CODE96; CHECK-NEXT: Relocations:97; CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_SLEB98; CHECK-NEXT: Index: 199; CHECK-NEXT: Offset: 0x4100; CHECK-NEXT: - Type: R_WASM_FUNCTION_INDEX_LEB101; CHECK-NEXT: Index: 2102; CHECK-NEXT: Offset: 0xA103; CHECK-NEXT: - Type: R_WASM_FUNCTION_INDEX_LEB104; CHECK-NEXT: Index: 4105; CHECK-NEXT: Offset: 0x13106; CHECK-NEXT: - Type: R_WASM_FUNCTION_INDEX_LEB107; CHECK-NEXT: Index: 5108; CHECK-NEXT: Offset: 0x1A109; CHECK-NEXT: - Type: R_WASM_MEMORY_ADDR_SLEB110; CHECK-NEXT: Index: 7111; CHECK-NEXT: Offset: 0x26112; CHECK-NEXT: Functions:113; CHECK-NEXT: - Index: 3114; CHECK-NEXT: Locals:115; CHECK-NEXT: Body: 4180808080001080808080000B116; CHECK-NEXT: - Index: 4117; CHECK-NEXT: Locals:118; CHECK-NEXT: Body: 1081808080001A1082808080001A41010B119; CHECK-NEXT: - Index: 5120; CHECK-NEXT: Locals:121; CHECK-NEXT: Body: 4187808080000B122; NORMAL-NEXT: - Type: DATA123; NORMAL-NEXT: Relocations:124; NORMAL-NEXT: - Type: R_WASM_TABLE_INDEX_I32125; NORMAL-NEXT: Index: 3126; NORMAL-NEXT: Offset: 0x1A127; NORMAL-NEXT: - Type: R_WASM_TABLE_INDEX_I32128; NORMAL-NEXT: Index: 4129; NORMAL-NEXT: Offset: 0x23130; NORMAL-NEXT: - Type: R_WASM_TABLE_INDEX_I32131; NORMAL-NEXT: Index: 5132; NORMAL-NEXT: Offset: 0x2C133; NORMAL-NEXT: - Type: R_WASM_MEMORY_ADDR_I32134; NORMAL-NEXT: Index: 12135; NORMAL-NEXT: Offset: 0x35136; NORMAL-NEXT: Segments:137; NORMAL-NEXT: - SectionOffset: 6138; NORMAL-NEXT: InitFlags: 0139; NORMAL-NEXT: Offset:140; NORMAL-NEXT: Opcode: I32_CONST141; NORMAL-NEXT: Value: 0142; NORMAL-NEXT: Content: 68656C6C6F0A00143; NORMAL-NEXT: - SectionOffset: 18144; NORMAL-NEXT: InitFlags: 0145; NORMAL-NEXT: Offset:146; NORMAL-NEXT: Opcode: I32_CONST147; NORMAL-NEXT: Value: 7148; NORMAL-NEXT: Content: '616263'149; NORMAL-NEXT: - SectionOffset: 26150; NORMAL-NEXT: InitFlags: 0151; NORMAL-NEXT: Offset:152; NORMAL-NEXT: Opcode: I32_CONST153; NORMAL-NEXT: Value: 12154; NORMAL-NEXT: Content: '01000000'155; NORMAL-NEXT: - SectionOffset: 35156; NORMAL-NEXT: InitFlags: 0157; NORMAL-NEXT: Offset:158; NORMAL-NEXT: Opcode: I32_CONST159; NORMAL-NEXT: Value: 16160; NORMAL-NEXT: Content: '02000000'161; NORMAL-NEXT: - SectionOffset: 44162; NORMAL-NEXT: InitFlags: 0163; NORMAL-NEXT: Offset:164; NORMAL-NEXT: Opcode: I32_CONST165; NORMAL-NEXT: Value: 20166; NORMAL-NEXT: Content: '03000000'167; NORMAL-NEXT: - SectionOffset: 53168; NORMAL-NEXT: InitFlags: 0169; NORMAL-NEXT: Offset:170; NORMAL-NEXT: Opcode: I32_CONST171; NORMAL-NEXT: Value: 24172; NORMAL-NEXT: Content: '00000000'173; NORMAL-NEXT: - Type: CUSTOM174; NORMAL-NEXT: Name: linking175; NORMAL-NEXT: Version: 2176; NORMAL-NEXT: SymbolTable:177; NORMAL-NEXT: - Index: 0178; NORMAL-NEXT: Kind: FUNCTION179; NORMAL-NEXT: Name: hello180; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ]181; NORMAL-NEXT: Function: 3182; NORMAL-NEXT: - Index: 1183; NORMAL-NEXT: Kind: DATA184; NORMAL-NEXT: Name: hello_str185; NORMAL-NEXT: Flags: [ ]186; NORMAL-NEXT: Segment: 0187; NORMAL-NEXT: Size: 7188; NORMAL-NEXT: - Index: 2189; NORMAL-NEXT: Kind: FUNCTION190; NORMAL-NEXT: Name: puts191; NORMAL-NEXT: Flags: [ UNDEFINED ]192; NORMAL-NEXT: Function: 0193; NORMAL-NEXT: - Index: 3194; NORMAL-NEXT: Kind: FUNCTION195; NORMAL-NEXT: Name: my_func196; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN, NO_STRIP ]197; NORMAL-NEXT: Function: 4198; NORMAL-NEXT: - Index: 4199; NORMAL-NEXT: Kind: FUNCTION200; NORMAL-NEXT: Name: foo_import201; NORMAL-NEXT: Flags: [ UNDEFINED ]202; NORMAL-NEXT: Function: 1203; NORMAL-NEXT: - Index: 5204; NORMAL-NEXT: Kind: FUNCTION205; NORMAL-NEXT: Name: bar_import206; NORMAL-NEXT: Flags: [ BINDING_WEAK, UNDEFINED ]207; NORMAL-NEXT: Function: 2208; NORMAL-NEXT: - Index: 6209; NORMAL-NEXT: Kind: FUNCTION210; NORMAL-NEXT: Name: func_comdat211; NORMAL-NEXT: Flags: [ BINDING_WEAK ]212; NORMAL-NEXT: Function: 5213; NORMAL-NEXT: - Index: 7214; NORMAL-NEXT: Kind: DATA215; NORMAL-NEXT: Name: data_comdat216; NORMAL-NEXT: Flags: [ BINDING_WEAK ]217; NORMAL-NEXT: Segment: 1218; NORMAL-NEXT: Size: 3219; NORMAL-NEXT: - Index: 8220; NORMAL-NEXT: Kind: DATA221; NORMAL-NEXT: Name: func_addr1222; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ]223; NORMAL-NEXT: Segment: 2224; NORMAL-NEXT: Size: 4225; NORMAL-NEXT: - Index: 9226; NORMAL-NEXT: Kind: DATA227; NORMAL-NEXT: Name: func_addr2228; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ]229; NORMAL-NEXT: Segment: 3230; NORMAL-NEXT: Size: 4231; NORMAL-NEXT: - Index: 10232; NORMAL-NEXT: Kind: DATA233; NORMAL-NEXT: Name: func_addr3234; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ]235; NORMAL-NEXT: Segment: 4236; NORMAL-NEXT: Size: 4237; NORMAL-NEXT: - Index: 11238; NORMAL-NEXT: Kind: DATA239; NORMAL-NEXT: Name: data_addr1240; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ]241; NORMAL-NEXT: Segment: 5242; NORMAL-NEXT: Size: 4243; NORMAL-NEXT: - Index: 12244; NORMAL-NEXT: Kind: DATA245; NORMAL-NEXT: Name: data_import246; NORMAL-NEXT: Flags: [ UNDEFINED ]247; NORMAL-NEXT: SegmentInfo:248; NORMAL-NEXT: - Index: 0249; NORMAL-NEXT: Name: .rodata.hello_str250; NORMAL-NEXT: Alignment: 0251; NORMAL-NEXT: Flags: [ ]252; NORMAL-NEXT: - Index: 1253; NORMAL-NEXT: Name: .rodata.data_comdat254; NORMAL-NEXT: Alignment: 0255; NORMAL-NEXT: Flags: [ ]256; NORMAL-NEXT: - Index: 2257; NORMAL-NEXT: Name: .data.func_addr1258; NORMAL-NEXT: Alignment: 2259; NORMAL-NEXT: Flags: [ ]260; NORMAL-NEXT: - Index: 3261; NORMAL-NEXT: Name: .data.func_addr2262; NORMAL-NEXT: Alignment: 2263; NORMAL-NEXT: Flags: [ ]264; NORMAL-NEXT: - Index: 4265; NORMAL-NEXT: Name: .data.func_addr3266; NORMAL-NEXT: Alignment: 2267; NORMAL-NEXT: Flags: [ ]268; NORMAL-NEXT: - Index: 5269; NORMAL-NEXT: Name: .data.data_addr1270; NORMAL-NEXT: Alignment: 3271; NORMAL-NEXT: Flags: [ ]272; NORMAL-NEXT: Comdats:273; NORMAL-NEXT: - Name: func_comdat274; NORMAL-NEXT: Entries:275; NORMAL-NEXT: - Kind: FUNCTION276; NORMAL-NEXT: Index: 5277; NORMAL-NEXT: - Kind: DATA278; NORMAL-NEXT: Index: 1279; NORMAL-NEXT: - Type: CUSTOM280; NORMAL-NEXT: Name: name281; NORMAL-NEXT: FunctionNames:282; NORMAL-NEXT: - Index: 0283; NORMAL-NEXT: Name: puts284; NORMAL-NEXT: - Index: 1285; NORMAL-NEXT: Name: foo_import286; NORMAL-NEXT: - Index: 2287; NORMAL-NEXT: Name: bar_import288; NORMAL-NEXT: - Index: 3289; NORMAL-NEXT: Name: hello290; NORMAL-NEXT: - Index: 4291; NORMAL-NEXT: Name: my_func292; NORMAL-NEXT: - Index: 5293; NORMAL-NEXT: Name: func_comdat294; NORMAL-NEXT:...295