xref: /llvm-project/lld/test/ELF/defsym.s (revision ff7f97a8199e6e931f5ae2b1ec79e8a1eb9b05d6)
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-readelf -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-readelf -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+ --defsym foo2=foo1 2>&1 | FileCheck %s --check-prefix=ERR --strict-whitespace
15#      ERR:error: --defsym:1: = expected, but got +
16# ERR-NEXT:>>> ERR+
17# ERR-NEXT:>>>    ^
18
19# CHECK-DAG: 0000000000000123     0 NOTYPE  GLOBAL DEFAULT   ABS foo1
20# CHECK-DAG: 0000000000000123     0 NOTYPE  GLOBAL DEFAULT   ABS foo2
21
22## Check we can use foo2 and it that it is an alias for foo1.
23# USE:       Disassembly of section .text:
24# USE-EMPTY:
25# USE-NEXT:  <_start>:
26# USE-NEXT:    movl $0x123, %edx
27
28# RUN: ld.lld -o %t %t.o --defsym=foo2=1
29# RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=ABS
30
31# ABS: 0000000000000001     0 NOTYPE  GLOBAL DEFAULT   ABS foo2
32
33# RUN: ld.lld -o %t %t.o --defsym=foo2=foo1+5
34# RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=EXPR
35
36# EXPR-DAG: 0000000000000123     0 NOTYPE  GLOBAL DEFAULT   ABS foo1
37# EXPR-DAG: 0000000000000128     0 NOTYPE  GLOBAL DEFAULT   ABS foo2
38
39# RUN: not ld.lld -o /dev/null %t.o --defsym=foo2=und 2>&1 | FileCheck %s -check-prefix=ERR1
40# ERR1: error: --defsym:1: symbol not found: und
41
42# RUN: not ld.lld -o /dev/null %t.o --defsym=xxx=yyy,zzz 2>&1 | FileCheck %s -check-prefix=ERR2
43# ERR2: error: --defsym:1: EOF expected, but got ,
44
45# RUN: not ld.lld -o /dev/null %t.o --defsym=foo 2>&1 | FileCheck %s -check-prefix=ERR3
46# ERR3: error: --defsym:1: unexpected EOF
47
48# RUN: not ld.lld -o /dev/null %t.o --defsym= 2>&1 | FileCheck %s -check-prefix=ERR3
49
50.globl foo1
51 foo1 = 0x123
52
53.global _start
54_start:
55  movl $foo2, %edx
56