172 lines · plain
1# Test that linking without shared memory causes __tls_base to be2# internalized.3 4# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s5 6.globaltype __tls_base, i327 8.globl get_tls19get_tls1:10 .functype get_tls1 () -> (i32)11 global.get __tls_base12 i32.const tls1@TLSREL13 i32.add14 end_function15 16.globl get_tls1_got17get_tls1_got:18 .functype get_tls1_got () -> (i32)19 global.get tls1@GOT@TLS20 end_function21 22.section .data.no_tls,"",@23.globl no_tls24.p2align 225no_tls:26 .int32 4227 .size no_tls, 428 29.section .tdata.tls1,"T",@30.globl tls131.p2align 232tls1:33 .int32 4334 .size tls1, 235 36.section .custom_section.target_features,"",@37 .int8 238 .int8 4339 .int8 740 .ascii "atomics"41 .int8 4342 .int8 1143 .ascii "bulk-memory"44 45# RUN: wasm-ld --no-gc-sections --no-entry -o %t.wasm %t.o46# RUN: obj2yaml %t.wasm | FileCheck %s47# RUN: llvm-objdump --disassemble-symbols=get_tls1 --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s --check-prefixes DIS48 49# RUN: wasm-ld --experimental-pic -shared -o %t.so %t.o50# RUN: obj2yaml %t.so | FileCheck %s --check-prefixes=SHARED,PIC51 52# RUN: wasm-ld --experimental-pic --no-gc-sections --no-entry -pie -o %t-pie.wasm %t.o53# RUN: obj2yaml %t-pie.wasm | FileCheck %s --check-prefixes=PIE,PIC54 55# RUN: wasm-ld --experimental-pic --features=atomics,bulk-memory,extended-const --no-gc-sections --no-entry -pie -o %t-extended-const.wasm %t.o56# RUN: obj2yaml %t-extended-const.wasm | FileCheck %s --check-prefixes=EXT-CONST57 58# CHECK: - Type: GLOBAL59# __stack_pointer60# CHECK-NEXT: Globals:61# CHECK-NEXT: - Index: 062# CHECK-NEXT: Type: I3263# CHECK-NEXT: Mutable: true64# CHECK-NEXT: InitExpr:65# CHECK-NEXT: Opcode: I32_CONST66# CHECK-NEXT: Value: 6553667# __tls_base68# CHECK-NEXT: - Index: 169# CHECK-NEXT: Type: I3270# CHECK-NEXT: Mutable: false71# CHECK-NEXT: InitExpr:72# CHECK-NEXT: Opcode: I32_CONST73# CHECK-NEXT: Value: 6553674# GOT.data.internal.tls175# CHECK-NEXT: - Index: 276# CHECK-NEXT: Type: I3277# CHECK-NEXT: Mutable: false78# CHECK-NEXT: InitExpr:79# CHECK-NEXT: Opcode: I32_CONST80# CHECK-NEXT: Value: 6553681# CHECK-NEXT: - Type: EXPORT82 83# CHECK: - Type: DATA84# .data85# CHECK-NEXT: Segments:86# CHECK-NEXT: - SectionOffset: 887# CHECK-NEXT: InitFlags: 088# CHECK-NEXT: Offset:89# CHECK-NEXT: Opcode: I32_CONST90# CHECK-NEXT: Value: 6553691# CHECK-NEXT: Content: 2B00000092# .tdata93# CHECK-NEXT: - SectionOffset: 1994# CHECK-NEXT: InitFlags: 095# CHECK-NEXT: Offset:96# CHECK-NEXT: Opcode: I32_CONST97# CHECK-NEXT: Value: 6554098# CHECK-NEXT: Content: 2A00000099# CHECK-NEXT: - Type: CUSTOM100 101# The constant value here which we add to `__tls_base` should not be absolute102# but relative to `__tls_base`, in this case zero rather than 1024.103# DIS: <get_tls1>:104# DIS-EMPTY:105# DIS-NEXT: global.get 1106# DIS-NEXT: i32.const 0107# DIS-NEXT: i32.add108# DIS-NEXT: end109 110# In PIC mode we expect TLS data and non-TLS data to be merged into111# a single segment which is initialized via the __memory_base import112 113# SHARED: - Type: IMPORT114# SHARED-NEXT: Imports:115# SHARED-NEXT: - Module: env116# SHARED-NEXT: Field: memory117# SHARED-NEXT: Kind: MEMORY118# SHARED-NEXT: Memory:119# SHARED-NEXT: Minimum: 0x1120# SHARED-NEXT: - Module: env121# SHARED-NEXT: Field: __memory_base122# SHARED-NEXT: Kind: GLOBAL123# SHARED-NEXT: GlobalType: I32124 125# In SHARED mode we export the address of all data symbols.126# SHARED: - Type: EXPORT127# SHARED-NEXT: Exports:128# SHARED: - Name: tls1129# SHARED-NEXT: Kind: GLOBAL130# SHARED: - Name: no_tls131# SHARED-NEXT: Kind: GLOBAL132 133# In PIE mode we don't export data address by default.134# PIE: - Type: EXPORT135# PIE-NEXT: Exports:136# PIE-NEXT: - Name: memory137# PIE-NEXT: Kind: MEMORY138# PIE-NEXT: Index: 0139# PIE-NEXT: - Type:140 141# .tdata and .data are combined into single segment in PIC mode.142# PIC: - Type: DATA143# PIC-NEXT: Segments:144# PIC-NEXT: - SectionOffset: 6145# PIC-NEXT: InitFlags: 0146# PIC-NEXT: Offset:147# PIC-NEXT: Opcode: GLOBAL_GET148# PIC-NEXT: Index: {{\d*}}149# PIC-NEXT: Content: 2B0000002A000000150# PIC-NEXT: - Type: CUSTOM151 152# Unless we have extended-const, in which case the merging is not needed.153# The first segment is placed directly at `__memory_base` and the second154# one is offset from `__memory_base` using `i32.add` and a constant.155 156# EXT-CONST: - Type: DATA157# EXT-CONST-NEXT: Segments:158# EXT-CONST-NEXT: - SectionOffset: 6159# EXT-CONST-NEXT: InitFlags: 0160# EXT-CONST-NEXT: Offset:161# EXT-CONST-NEXT: Opcode: GLOBAL_GET162# EXT-CONST-NEXT: Index: 1163# EXT-CONST-NEXT: Content: 2B000000164# EXT-CONST-NEXT: - SectionOffset: 18165# EXT-CONST-NEXT: InitFlags: 0166# EXT-CONST-NEXT: Offset:167# EXT-CONST-NEXT: Extended: true168# This instruction sequence decodes to:169# (global.get[0x23] 0x1 i32.const[0x41] 0x04 i32.add[0x6A] end[0x0b])170# EXT-CONST-NEXT: Body: 230141046A0B171# EXT-CONST-NEXT: Content: 2A000000172