xref: /llvm-project/lld/test/ELF/linkerscript/defined.test (revision 65a15a56d5ca0d26ca6d34c31a617f5b26e3cfee)
1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/define.s -o %t.o
3# RUN: ld.lld -o %t --defsym vv=1 --script %s %t.o
4# RUN: llvm-readelf -S -s %t | FileCheck %s
5
6# CHECK:      [Nr] Name   Type     Address          Off    Size   ES Flg Lk Inf Al
7# CHECK-NEXT: [ 0]        NULL     0000000000000000 000000 000000 00      0   0  0
8# CHECK-NEXT: [ 1] .foo   PROGBITS 0000000000011000 001000 000008 00   A  0   0  1
9# CHECK-NEXT: [ 2] .bar   PROGBITS 0000000000013000 003000 000008 00   A  0   0  1
10# CHECK-NEXT: [ 3] .test  PROGBITS 0000000000015000 005000 000008 00   A  0   0  1
11# CHECK-NEXT: [ 4] .text  PROGBITS 0000000000015008 005008 000000 00  AX  0   0  4
12
13# CHECK:         Value          Size Type    Bind   Vis       Ndx Name
14# CHECK-DAG:  0000000000000001     0 NOTYPE  GLOBAL DEFAULT   ABS vv
15# CHECK-DAG:  0000000000000009     0 NOTYPE  GLOBAL DEFAULT   ABS ww
16# CHECK-DAG:  0000000000000001     0 NOTYPE  GLOBAL DEFAULT   ABS x1
17# CHECK-DAG:  0000000000000002     0 NOTYPE  GLOBAL DEFAULT   ABS x2
18# CHECK-DAG:  0000000000000001     0 NOTYPE  GLOBAL DEFAULT   ABS y1
19# CHECK-DAG:  0000000000000002     0 NOTYPE  GLOBAL DEFAULT   ABS y2
20
21EXTERN(extern_defined)
22SECTIONS {
23  . = DEFINED(defined) ? 0x11000 : .;
24  .foo : { *(.foo*) }
25  . = DEFINED(notdefined) ? 0x12000 : 0x13000;
26  .bar : { *(.bar*) }
27  . = DEFINED(extern_defined) ? 0x14000 : 0x15000;
28
29## Take the value from --defsym.
30  vv = DEFINED(vv) ? vv : 9;
31## 9 as ww is undefined.
32  ww = DEFINED(ww) ? ww : 9;
33
34## 1 as xx is not yet defined.
35  x1 = DEFINED(xx) ? 2 : 1;
36  .test : {
37    xx = .;
38    *(.test*)
39  }
40  x2 = DEFINED(xx) ? 2 : 1;
41
42  y1 = DEFINED(yy) ? 2 : 1;
43  yy = .;
44  y2 = DEFINED(yy) ? 2 : 1;
45}
46