1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
3# RUN: echo 'movq tls1@GOTTPOFF(%rip), %rax' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
4# RUN: ld.lld %t1.o %t.o -o /dev/null
5# RUN: ld.lld %t.o %t1.o -o /dev/null
6# RUN: ld.lld --start-lib %t.o --end-lib %t1.o -o /dev/null
7# RUN: ld.lld %t1.o --start-lib %t.o --end-lib -o /dev/null
8
9## The TLS definition mismatches a non-TLS reference.
10# RUN: echo '.type tls1,@object; movq tls1,%rax' | llvm-mc -filetype=obj -triple=x86_64 - -o %t2.o
11# RUN: not ld.lld %t2.o %t.o -o /dev/null 2>&1 | FileCheck %s
12## We fail to flag the swapped case.
13# RUN: ld.lld %t.o %t2.o -o /dev/null
14
15## We fail to flag the STT_NOTYPE reference. This usually happens with hand-written
16## assembly because compiler-generated code properly sets symbol types.
17# RUN: echo 'movq tls1,%rax' | llvm-mc -filetype=obj -triple=x86_64 - -o %t3.o
18# RUN: ld.lld %t3.o %t.o -o /dev/null
19
20## Overriding a TLS definition with a non-TLS definition does not make sense.
21# RUN: not ld.lld --defsym tls1=42 %t.o -o /dev/null 2>&1 | FileCheck %s
22
23## Part of PR36049: This should probably be allowed.
24# RUN: not ld.lld --defsym tls1=tls2 %t.o -o /dev/null 2>&1 | FileCheck %s
25
26## An undefined symbol in module-level inline assembly of a bitcode file
27## is considered STT_NOTYPE. We should not error.
28# RUN: echo 'target triple = "x86_64-pc-linux-gnu" \
29# RUN:   target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" \
30# RUN:   module asm "movq tls1@GOTTPOFF(%rip), %rax"' | llvm-as - -o %t.bc
31# RUN: ld.lld %t.o %t.bc -o /dev/null
32# RUN: ld.lld %t.bc %t.o -o /dev/null
33
34# CHECK: error: TLS attribute mismatch: tls1
35
36.globl _start
37_start:
38  addl $1, %fs:tls1@TPOFF
39  addl $2, %fs:tls2@TPOFF
40
41.tbss
42.globl tls1, tls2
43  .space 8
44tls1:
45  .space 4
46tls2:
47  .space 4
48