1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
3# RUN: ld.lld -o %t %t.o --defsym=foo2=foo1
4# RUN: llvm-readobj --symbols -S %t | FileCheck %s
5# RUN: llvm-objdump -d --print-imm-hex %t | FileCheck %s --check-prefix=USE
6
7## Check that we accept --defsym foo2=foo1 form.
8# RUN: ld.lld -o %t2 %t.o --defsym foo2=foo1
9# RUN: llvm-readobj --symbols -S %t2 | FileCheck %s
10# RUN: llvm-objdump -d --print-imm-hex %t2 | FileCheck %s --check-prefix=USE
11
12## Check we are reporting the error correctly and don't crash
13## when handling the second --defsym.
14# RUN: not ld.lld -o /dev/null %t.o --defsym ERR+ \
15#        --defsym foo2=foo1 2>&1 | FileCheck %s --check-prefix=ERR
16# ERR: error: -defsym: syntax error: ERR+
17
18# CHECK:      Symbol {
19# CHECK:        Name: foo1
20# CHECK-NEXT:   Value: 0x123
21# CHECK-NEXT:   Size:
22# CHECK-NEXT:   Binding: Global
23# CHECK-NEXT:   Type:
24# CHECK-NEXT:   Other:
25# CHECK-NEXT:   Section: Absolute
26# CHECK-NEXT: }
27# CHECK-NEXT: Symbol {
28# CHECK-NEXT:   Name: foo2
29# CHECK-NEXT:   Value: 0x123
30# CHECK-NEXT:   Size:
31# CHECK-NEXT:   Binding: Global
32# CHECK-NEXT:   Type:
33# CHECK-NEXT:   Other:
34# CHECK-NEXT:   Section: Absolute
35# CHECK-NEXT: }
36
37## Check we can use foo2 and it that it is an alias for foo1.
38# USE:       Disassembly of section .text:
39# USE-EMPTY:
40# USE-NEXT:  <_start>:
41# USE-NEXT:    movl $0x123, %edx
42
43# RUN: ld.lld -o %t %t.o --defsym=foo2=1
44# RUN: llvm-readobj --symbols -S %t | FileCheck %s --check-prefix=ABS
45
46# ABS:      Symbol {
47# ABS:        Name: foo2
48# ABS-NEXT:   Value: 0x1
49# ABS-NEXT:   Size:
50# ABS-NEXT:   Binding: Global
51# ABS-NEXT:   Type:
52# ABS-NEXT:   Other:
53# ABS-NEXT:   Section: Absolute
54# ABS-NEXT: }
55
56# RUN: ld.lld -o %t %t.o --defsym=foo2=foo1+5
57# RUN: llvm-readobj --symbols -S %t | FileCheck %s --check-prefix=EXPR
58
59# EXPR:      Symbol {
60# EXPR:        Name: foo1
61# EXPR-NEXT:   Value: 0x123
62# EXPR-NEXT:   Size:
63# EXPR-NEXT:   Binding: Global
64# EXPR-NEXT:   Type:
65# EXPR-NEXT:   Other:
66# EXPR-NEXT:   Section: Absolute
67# EXPR-NEXT: }
68# EXPR-NEXT: Symbol {
69# EXPR-NEXT:   Name: foo2
70# EXPR-NEXT:   Value: 0x128
71# EXPR-NEXT:   Size:
72# EXPR-NEXT:   Binding: Global
73# EXPR-NEXT:   Type:
74# EXPR-NEXT:   Other:
75# EXPR-NEXT:   Section: Absolute
76# EXPR-NEXT: }
77
78# RUN: not ld.lld -o /dev/null %t.o --defsym=foo2=und 2>&1 | FileCheck %s -check-prefix=ERR1
79# ERR1: error: -defsym:1: symbol not found: und
80
81# RUN: not ld.lld -o /dev/null %t.o --defsym=xxx=yyy,zzz 2>&1 | FileCheck %s -check-prefix=ERR2
82# ERR2: -defsym:1: EOF expected, but got ,
83
84# RUN: not ld.lld -o /dev/null %t.o --defsym=foo 2>&1 | FileCheck %s -check-prefix=ERR3
85# ERR3: error: -defsym: syntax error: foo
86
87# RUN: not ld.lld -o /dev/null %t.o --defsym= 2>&1 | FileCheck %s -check-prefix=ERR4
88# ERR4: error: -defsym: syntax error:
89
90.globl foo1
91 foo1 = 0x123
92
93.global _start
94_start:
95  movl $foo2, %edx
96