1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
3
4## Check that padding value works:
5# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x1122 }" > %t.script
6# RUN: ld.lld -o %t.out --script %t.script %t
7# RUN: llvm-objdump -s %t.out | FileCheck --check-prefix=YES %s
8# YES: 66000011 22000011 22000011 22000011
9
10# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =(0x1100+0x22) }" > %t.script
11# RUN: ld.lld -o %t.out --script %t.script %t
12# RUN: llvm-objdump -s %t.out | FileCheck --check-prefix=YES2 %s
13# YES2: 66000011 22000011 22000011 22000011
14
15## Confirming that address was correct:
16# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x99887766 }" > %t.script
17# RUN: ld.lld -o %t.out --script %t.script %t
18# RUN: llvm-objdump -s %t.out | FileCheck --check-prefix=YES3 %s
19# YES3: 66998877 66998877 66998877 66998877
20
21## Default padding value is 0x00:
22# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } }" > %t.script
23# RUN: ld.lld -o %t.out --script %t.script %t
24# RUN: llvm-objdump -s %t.out | FileCheck --check-prefix=NO %s
25# NO: 66000000 00000000 00000000 00000000
26
27## Decimal value.
28# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =777 }" > %t.script
29# RUN: ld.lld -o %t.out --script %t.script %t
30# RUN: llvm-objdump -s %t.out | FileCheck --check-prefix=DEC %s
31# DEC: 66000003 09000003 09000003 09000003
32
33## Invalid hex value:
34# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x99XX }" > %t.script
35# RUN: not ld.lld -o /dev/null --script %t.script %t 2>&1 \
36# RUN:   | FileCheck --check-prefix=ERR2 %s
37# ERR2: malformed number: 0x99XX
38
39## Check case with space between '=' and a value:
40# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } = 0x1122 }" > %t.script
41# RUN: ld.lld -o %t.out --script %t.script %t
42# RUN: llvm-objdump -s %t.out | FileCheck --check-prefix=YES %s
43
44## Check case with optional comma following output section command:
45# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x1122, .a : { *(.a*) } }" > %t.script
46# RUN: ld.lld -o %t.out --script %t.script %t
47# RUN: llvm-objdump -s %t.out | FileCheck --check-prefix=YES %s
48
49## Check we can use an artbitrary expression as a filler.
50# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } = ((0x11<<8) | 0x22) }" > %t.script
51# RUN: ld.lld -o %t.out --script %t.script %t
52# RUN: llvm-objdump -s %t.out | FileCheck --check-prefix=YES %s
53
54## Check case with space between '=' and expression:
55# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =((0x11 << 8) | 0x22) }" > %t.script
56# RUN: ld.lld -o %t.out --script %t.script %t
57# RUN: llvm-objdump -s %t.out | FileCheck --check-prefix=YES %s
58
59## Check we report an error if expression value is larger than 32-bits.
60# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =(0x11 << 32) }" > %t.script
61# RUN: not ld.lld -o /dev/null --script %t.script %t 2>&1 | FileCheck --check-prefix=ERR3 %s
62# ERR3: filler expression result does not fit 32-bit: 0x1100000000
63
64## Check we report an error if an expression use a symbol.
65# RUN: echo "SECTIONS { foo = 0x11; .mysec : { *(.mysec*) } = foo }" > %t.script
66# RUN: not ld.lld -o /dev/null %t --script %t.script 2>&1 | FileCheck --check-prefix=ERR4 %s
67# ERR4: symbol not found: foo
68
69## Check we are able to parse scripts where "/DISCARD/" follows a section fill expression.
70# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x1122 /DISCARD/ : { *(.text) } }" > %t.script
71# RUN: ld.lld -o %t.out --script %t.script %t
72# RUN: llvm-objdump -s %t.out | FileCheck --check-prefix=YES %s
73
74.section        .mysec.1,"a"
75.align  16
76.byte   0x66
77
78.section        .mysec.2,"a"
79.align  16
80.byte   0x66
81
82.globl _start
83_start:
84 nop
85