[llvm] Do not replace dead constant references in metadata with undef
[llvm-project.git] / lld / test / ELF / linkerscript / sections-padding.s
blob4d147d79c63e6d1139c9664ff5b4d38aedc35b73
1 # REQUIRES: x86
2 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
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
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
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
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
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
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
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
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
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
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
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
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
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
74 .section .mysec.1,"a"
75 .align 16
76 .byte 0x66
78 .section .mysec.2,"a"
79 .align 16
80 .byte 0x66
82 .globl _start
83 _start:
84 nop